[pdftex] how to embed mp3 into pdf using pdfTeX?

Vit Zyka vit.zyka at seznam.cz
Mon Dec 6 15:25:51 CET 2004


Tigran Aivazian wrote:

> Is it possible to embed mp3 files (and make them playable from within 
> Acrobat Reader) into a pdf file?

I did it only with RAW sound file (wav without header). It operates in 
AR 4,5,6/Win (Mac not tested).

The code is bellow (sorry, no package).

Vit Zyka

-----------------------------------------

% main macro
\def\insertRawSound#1#2#3#4#5{% 1-rate 2-cannels 3-bits 4-file 5-label
   \immediate\pdfobj stream
     attr{/Type /Sound /R #1 /C #2 /B #3 /E /Signed } file{#4}
   \immediate\pdfobj{<< /S /Sound /Sound \the\pdflastobj\space 0 R >>}
   \edef#5{\the\pdflastobj}}

% only for automatic sound playing with every new page
\def\autoObject#1{%
   \edef\pdfpageattrbody{{/AA << /O #1 0 R >>}}
   \expandafter\global\expandafter\pdfpageattr\pdfpageattrbody}
\def\autoOpenCloseObject#1#2{%
   \edef\pdfpageattrbody{{/AA << /O #1 0 R /C #2 0 R >>}}
   \expandafter\global\expandafter\pdfpageattr\pdfpageattrbody}
\def\autoObjectStop{\global\pdfpageattr{}}

% usage:
\insertRawSound{22050}{1}{16}{file.raw}{idSound}
\insertRawSound{22050}{1}{16}{empty.raw}{idEmptySound}
\autoOpenCloseObject{idSound}{idEmptySound}

-----------------

empty.raw is sound file with only one silent sample. That is a trick how 
to stop playing file.raw when going to next page.

-- 
Vít Zýka --- http://typokvitek.com
     Automatic document typesetting
     Automaticka sazba dokumentu --
--





More information about the pdftex mailing list