Play embedded media with xelatex #258
-
First of all, thank you for making this awesome tool! I am using it regularly for my presentations at uni and am unbelievably happy with it. There is just one tiny thing I am struggling with: embedding media. At the moment, it seems like you can't embed audio or video files with xelatex in such a way that it is played by
If I can be of any help, feel free to let me know! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
If I recall correctly, the issue is the way in which the video file is embedded, which differs from across different packages. media9 wraps the movie in a flash media-player object which makes it very annoying.
I think the main appeal was to have a media player with the same functionality, look & feel, etc. across all platforms and PDF readers. Alternatives are:
|
Beta Was this translation helpful? Give feedback.
-
The \documentclass{beamer}
\usepackage{xkeyval}
\usepackage{zref-abspage}
\usepackage[bigfiles]{pdfbase}
% Written by Fritz -- https://tex.stackexchange.com/a/592827-- using Adobe PDF Reference, sixth edition, Nov. 2006
% Usage: \simplemedia[<options>]{<poster or text>}{<media file>}{MIME type}
\makeatletter
\define@boolkey{simplemedia}{autoplay}{\def\simplemediaautoplay{#1}}
\define@boolkey{simplemedia}{showGUI}{\def\simplemediashowGUI{#1}}
\presetkeys{simplemedia}{autoplay=false,showGUI=false}{}
\ExplSyntaxOn
\newcommand\simplemedia[4][]{%
\setkeys{simplemedia}{#1}\leavevmode
\pbs_pdfobj:nnn{}{fstream}{{}{#3}} % EmbeddedFiles stream
\pbs_pdfobj:nnn{}{dict}{/Type/Filespec/F~(#3)/UF~(#3)/EF~<</F~\pbs_pdflastobj:>>} % File specification dictionary
\pbs_pdfobj:nnn{}{dict}{/CT~(#4)/D~\pbs_pdflastobj:/N~(Media~clip~from~#3)/P~<</TF (TEMPACCESS)>>/S~/MCD} % Content type dictionary
% XXX: /A below is incorrectly interpreted by Pympress as autoplay instead of play-on-activate and using the Additional Actions (AA) dictionary for autoplay
\pbs_pdfobj:nnn{}{dict}{/C~\pbs_pdflastobj:/N~(Rendition~from~#3)/P~<</BE~<</C~\simplemediashowGUI~/A~\simplemediaautoplay>>~>>/S~/MR} % media clip dictionary
\tl_set:Nx\mediarendition{\pbs_pdflastobj:}% Save ID of Rendition annotation
\pbs_pdfobj:nnn{}{dict}{}\tl_set:Nx\renditionactionplay{\pbs_pdflastobj:}% Reserve ID for Play Rendition action
\pbs_pdfobj:nnn{}{dict}{}\tl_set:Nx\renditionactionstop{\pbs_pdflastobj:}% Reserve ID for Stop Rendition action
\hbox_set:Nn\l_tmpa_box{#2}% Compute size of poster
\tl_set:Nx\l_box_wd_tl{\dim_use:N\box_wd:N\l_tmpa_box}
\tl_set:Nx\l_box_ht_tl{\dim_use:N\box_ht:N\l_tmpa_box}
\tl_set:Nx\l_box_dp_tl{\dim_use:N\box_dp:N\l_tmpa_box}
\pbs_pdfxform:nnnnn{1}{1}{}{}{\l_tmpa_box}
\tl_set:Nx\l_simplem_current_page_tl{\zref@extract{simplem@\int_use:N\g_simplem_id_int}{abspage}}
\pbs_pdfannot:nnnn{\l_box_wd_tl}{\l_box_ht_tl}{\l_box_dp_tl}{
/T~(Annotation~from~#3)~/Subtype~/Screen~/BS~<</W~1/S/S>>/C~[0.039216~0.039216~0.039216]/CA~1/F~4~%
/Contents~(Embedded~media~file~#3)/NM~(simplemediascreenannot:#3)/AP~<</N~\pbs_pdflastxform:>>%
/A~\renditionactionplay~/AA~<<\ifKV@simplemedia@autoplay~/PO~\renditionactionplay~\fi~/PC~\renditionactionstop~>>~%
\int_compare:nT{\l_simplem_current_page_tl>0}{/P~\exp_args:Ne\pdf_pageobject_ref:n{\l_simplem_current_page_tl}}%
}
\pbs_pdfobj:nnn{\renditionactionplay}{dict}{/R~\mediarendition/S~/Rendition/OP~4/AN~\pbs_pdflastann:} % Rendition Action: "Play Rendition"
\pbs_pdfobj:nnn{\renditionactionstop}{dict}{/R~\mediarendition/S~/Rendition/OP~1/AN~\pbs_pdflastann:} % Rendition Action: "Stop Rendition"
\phantom{#2} % Display the poster
\zref@labelbyprops{simplem@\int_use:N\g_simplem_id_int}{abspage}\int_gincr:N\g_simplem_id_int
}%
\int_new:N\g_simplem_id_int
\ExplSyntaxOff
\makeatother
\begin{document}
\begin{frame}
\frametitle{play on click}
\begin{center}
\simplemedia{\includegraphics[width=5cm]{example.png}}{example.mp4}{video/mp4}
\end{center}
\end{frame}
\begin{frame}
\frametitle{autoplay}
\begin{center}
\simplemedia[autoplay=true]{\includegraphics[width=5cm]{example.png}}{example.mp4}{video/mp4}
\end{center}
\end{frame}
\begin{frame}
\frametitle{show GUI}
\begin{center}
\simplemedia[showGUI=true]{\includegraphics[width=5cm]{example.png}}{example.mp4}{video/mp4}
\end{center}
\end{frame}
\end{document} When pympress is fixed, and to have correct behaviour on other PDF players, |
Beta Was this translation helpful? Give feedback.
-
This is great, thank you so much for your efforts! Once the bug is fixed, could you release a new version, please? |
Beta Was this translation helpful? Give feedback.
-
Once it’s fixed I will update this code and put it somewhere in the documentation. However, the fix is likely going to either not be easy, or to break autoplay, so I may hold off for a while. |
Beta Was this translation helpful? Give feedback.
The
\simplemedia
approach by user Fritz on the stackexchange question works under XeLaTeX. It revealed there’s a bug in pympress auto-play I’ll get around to fixing later on. In the mean time this code works (I’ve made the original code a little bit denser):