Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play embedded media with xelatex #253

Closed
opensource-philosophy opened this issue Oct 16, 2022 · 4 comments
Closed

Play embedded media with xelatex #253

opensource-philosophy opened this issue Oct 16, 2022 · 4 comments

Comments

@opensource-philosophy
Copy link

opensource-philosophy commented Oct 16, 2022

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 pympress. The reason for this is that the multimedia package, for which there are examples in the README-file, does not work with xelatex, throwing error messages, and media embedded using media9, which does work with xelatex, is not clickable in pympress (although it is in other pdf viewers such as Okular). Thus, I have two questions:

  1. Is there a way pympress supports the package media9? It seems to be the newest, most versatile and most popular package for embedding media files in beamer.
  2. If not, are you aware of any other way to embed media with xelatex in such a way that pympress recognizes it?

If I can be of any help, feel free to let me know!

@Cimbali
Copy link
Owner

Cimbali commented Oct 16, 2022

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.

  • Actually executing flash is probably undesirable (lots of work, maybe shipping flash runtimes, security issues…)
  • Flash itself is actually deprecated since it reached end of life in Dec. 2020
  • Extracting the info from the flash object to interpret what it meant on our own is also quite a lot of work and will necessarily be incomplete or break often (any scripting for autoplay or other features will never be available).

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:

@Cimbali
Copy link
Owner

Cimbali commented Nov 21, 2022

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):

\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, /A~\simplemediaautoplay should be /A~true.

@opensource-philosophy
Copy link
Author

This is great, thank you so much for your efforts! Once the bug is fixed, could you release a new version, please?

@Cimbali
Copy link
Owner

Cimbali commented Nov 22, 2022

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.

Repository owner locked and limited conversation to collaborators Nov 22, 2022
@Cimbali Cimbali converted this issue into discussion #258 Nov 22, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants