%%
%% This is file `yt4pdf.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% yt4pdf.dtx  (with options: `copyright,package')
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% yt4pdf.sty package,             2010-09-10           %%
%% Copyright (C) 2010  D. P. Story                      %%
%%   [email protected]                                 %%
%%                                                      %%
%% This program can redistributed and/or modified under %%
%% the terms of the LaTeX Project Public License        %%
%% Distributed from CTAN archives in directory          %%
%% macros/latex/base/lppl.txt; either version 1 of the  %%
%% License, or (at your option) any later version.      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}[1997/12/01]
\ProvidesPackage{yt4pdf}
[2016/10/04 v1.1 yt4pdf: Play You Tube videos in PDF, Acrobat Distiller only (dps)]
\RequirePackage{xkeyval}
\ProcessOptions
\RequirePackage{rmannot}
\RequirePackage{popupmenu}[2010/09/18]
\newcommand{\ytFolder}{C:/Users/Public/Documents/My TeX Files/%
tex/latex/aeb/aebpro/yt4pdf/swf}
\saveNamedPath{ytSWF}{\ytFolder/pdf_tube_basic.swf}
\InputIfFileExists{yt4pdf.cfg}{}{}
\def\yt@namegdef#1{\expandafter\gdef\csname #1\endcsname}
\def\yt@namexdef#1{\expandafter\xdef\csname #1\endcsname}
\def\thisNamedRMA(#1){this.getAnnotRichMedia(this.pageNum,"#1")}
\define@key{ytRmAnnot}{play}[]{\def\ytrmannot@play{#1}}
\define@key{ytRmAnnot}{load}[]{\def\ytrmannot@load{#1}}
\setkeys{ytRmAnnot}{play,load}
\let\ytCurrRMAName\@empty
\newcommand{\ytRmAnnot}[4][]{\begingroup
   \@ifundefined{#2@ytrmname}{\yt@namegdef{#2@ytrmname}{#1}}%
   {\PackageError{yt2pdf}{The name `#2' is already defined
   for\MessageBreak this \string\ytRmAnnot}{Choose a unique
   name for this \string\ytRmAnnot, one different from `#2'.}}%
   \setkeys*{ytRmAnnot}{#1}\gdef\ytCurrRMAName{#2}%
   \ifx\ytrmannot@play\@empty\else
   \makebox[0pt][l]{\pushButton[\BC{}\BG{}\S{S}
   \AA{\AAPageOpen{aebStartPlayer(\thisNamedRMA(#2),%
   "\ytrmannot@play",true);}\AAPageClose{aebCancelWait(false);}}
   ]{btnRmAnnot#2}{1bp}{1bp}}\let\ytrmannot@load\@empty\fi
   \ifx\ytrmannot@load\@empty
   \else\makebox[0pt][l]{\pushButton[\BC{}\BG{}\S{S}
   \AA{\AAPageOpen{aebStartPlayer(\thisNamedRMA(#2),%
   "\ytrmannot@load",false);}\AAPageClose{aebCancelWait(false);}}
   ]{btnRmAnnot#2}{1bp}{1bp}}\fi
   \rmAnnot[\XKV@rm,name=#2,enabled=onclick]{#3}{#4}{ytSWF}%
   \endgroup
}
\newcommand{\DeclareYTName}[2][]{\def\argi{#1}%
   \ifx\argi\@empty\gdef\ytCurrRMAName{#2}\else
   \gdef\ytCurrRMAName{[#1]#2}\fi
}
\newcommand{\ytBtnPresets}[1]{\def\yt@Presets{#1}}
\ytBtnPresets{\BC{.5 0 0}\S{S}\textFont{HeBo}\autoCenter{n}}
\newcommand{\oyt@RMA}[1][this.pageNum]{\oyt@@RMA[#1]}
\def\oyt@@RMA[#1]#2\@nil{\gdef\yt@CurrRMAName{#2}%
   \def\yt@rm{this.getAnnotRichMedia(#1,"#2")}}
\newcommand{\ytPlayToggle}[3][]{%
   \expandafter\oyt@RMA\ytCurrRMAName\@nil%
   \pushButton[\CA{\ytStrPAUSE}\presets{\yt@Presets}#1
   \A{\JS{ytPlayToggle(\yt@rm);}}]{playToggle}{#2}{#3}%
}
\newcommand{\ytStopLoading}[3][]{%
   \expandafter\oyt@RMA\ytCurrRMAName\@nil%
   \pushButton[\CA{\ytStrStopLoading}\presets{\yt@Presets}#1
   \A{\JS{\[email protected]("stopVideo");}}]{vidStop}{#2}{#3}%
}
\newcommand{\ytMuteToggle}[3][]{%
   \expandafter\oyt@RMA\ytCurrRMAName\@nil%
   \pushButton[\CA{\ytStrMUTE}\presets{\yt@Presets}#1
   \A{\JS{ytMuteToggle(\yt@rm);}}]{muteToggle}{#2}{#3}%
}
\newcommand{\ytRewind}[3][]{%
   \expandafter\oyt@RMA\ytCurrRMAName\@nil%
   \pushButton[\CA{\ytStrREWIND}\presets{\yt@Presets}#1
   \A{\JS{ytRewind(\yt@rm);}}]{ytRewind}{#2}{#3}%
}
\newcommand{\ytSelect}[4][]{%
   \expandafter\oyt@RMA\ytCurrRMAName\@nil%
   \pushButton[\CA{\ytStrLoadVideo}\presets{\yt@Presets}#1
   \A{\JS{ytSelect(\yt@rm,"#2");}}]{selectVid}{#3}{#4}%
}
\newcommand{\ytOpenWeb}[3][]{%
   \expandafter\oyt@RMA\ytCurrRMAName\@nil%
   \pushButton[\CA{\ytStrWatchOnWeb}\presets{\yt@Presets}#1
   \A{\JS{ytOpenWeb(\yt@rm);}}]{playOnWeb}{#2}{#3}%
}
\newcommand{\ytvIdPresets}[1]{\def\yt@vIdPresets{#1}}
\ytvIdPresets{\linktxtcolor{webbrown}}
\newcommand{\ytvId}{\@ifstar{\def\yt@lnk@play{false}\yt@@vId}
   {\def\yt@lnk@play{true}\yt@@vId}}
\newcommand{\yt@@vId}[3][\ytCurrRMAName]{%
   \oyt@RMA#1\@nil\setLink[\presets{\yt@vIdPresets}
   \A{\JS{aebStartPlayer(\yt@rm,"#2",\yt@lnk@play);}}]{#3}}
\newcommand{\ytComboListPresets}[1]{\def\yt@ComboListPresets{#1}}
\newcommand{\ytComboBtnPresets}[1]{\def\yt@ComboBtnPresets{#1}}
\let\yt@ComboListPresets\@empty
\let\yt@ComboBtnPresets\@empty
\newcommand{\ytPlayList}{\begingroup\@makeother\_\@makeother\'
   \ytPlayList@i}
\def\ytPlayList@i#1#2{\gdef\yt@pl@def{#1}\xdef\yt@pl@pl{#2}\endgroup}
\newcommand{\declarePlayList}{\bgroup
   \@makeother\_\@makeother\-
   \yt@declarePlayList}
\def\yt@declarePlayList#1#2{%
   \gdef#1{#2}\egroup}
\newcommand{\ytIdTitle}[2]{[(#2)(#1)]}
\newcount\ytListCnt \ytListCnt=0
\newcommand{\ytNewBaseName}[1][]{%
   \def\yt@argi{#1}\ifx\yt@argi\@empty\global\advance\ytListCnt1\relax
       \gdef\yt@BaseName{\yt@CurrRMAName\the\ytListCnt}\else
       \gdef\yt@BaseName{\yt@CurrRMAName#1}\fi
}
\newcommand{\ytResetBaseName}{\gdef\yt@BaseName{\yt@CurrRMAName}}
\ytResetBaseName
\newcommand{\ytComboList}[3][]{%
   \expandafter\oyt@RMA\ytCurrRMAName\@nil%
   \comboBox[\DV{\yt@pl@def}\V{\yt@pl@def}
       \presets{\yt@ComboListPresets}#1]{ytSelect\yt@BaseName}
       {#2}{#3}{\yt@pl@pl}%
}
\newcommand{\ytComboBtn}[3][]{%
   \expandafter\oyt@RMA\ytCurrRMAName\@nil%
   \pushButton[\CA{\ytStrPLAY}\presets{\yt@ComboBtnPresets}#1
       \A{\JS{var f=this.getField("ytSelect\yt@BaseName");\r
       aebStartPlayer(\yt@rm,f.value,!event.shift);
   }}]{ytSelectBtn\yt@BaseName}{#2}{#3}%
}
\newcommand{\ytPopupMenuData}[1]{{\toks0={// yt4pdf: Begin popup menu data^^J}%
   \@tfor\yt@menu:=#1\do{%
       \toks2=\expandafter{\yt@menu}%
       \edef\@tmp@exp{\the\toks0\the\toks2^^J}%
       \toks0=\expandafter{\@tmp@exp}%
   }\xdef\ytPopupData{\the\toks0// End of popup menu data}%
}}
\def\ytPopupData{// No popup menu data defined}%
\newcommand{\puIdTitle}[2]{\item{title={#1},return={[\itemindex,'#2']}}}
\newcommand{\ytStrPLAY}{PLAY}
\newcommand{\ytStrREPLAY}{REPLAY}
\newcommand{\ytStrPAUSE}{PAUSE}
\newcommand{\ytStrBuffering}{Buffering...}
\newcommand{\ytStrStopLoading}{Stop Loading}
\newcommand{\ytStrMUTE}{MUTE}
\newcommand{\ytStrUNMUTE}{UNMUTE}
\newcommand{\ytStrREWIND}{REWIND}
\newcommand{\ytStrLoadVideo}{Load Video}
\newcommand{\ytStrWatchOnWeb}{Watch on YouTube}
\newcommand{\ytRespQues}{Enter the YouTube Video ID}
\newcommand{\ytRespTitle}{Load a Video}
\newcommand{\ytRespLabel}{ID:}
\newcommand{\ytStrErrorVideoNotFound}{Error: Video not found}
\newcommand{\ytStrErrorNoEmbed}{Error: This video does not allow
   embedded playback \r\r Would you like to view this video
   on the web?}
\newcommand{\ytStrConnecTimedOut}{Connection timed out, try again.}
\begin{insDLJS*}[ytPlayToggle]{yt}
\begin{newsegment}{yt4PDF: YouTube for PDF JavaScript}
/*
   Document-level script for YouTube player
   Document-level script for the PDFtube embedded YouTube player
   ***************************************************************
   Functions to be called by buttons or links on the PDF
   in each case, "rm" is the RichMedia annot containing the player
   All these are optional and can be renamed or edited as required
   ***********************************************************
*/
// toggle play/pause (button labels updated by event functions)
function ytPlayToggle(rm) {
   var ps = rm.callAS("getPlayerState");
   rm.callAS((ps == 1)? "pauseVideo" : "playVideo");
}
// toggle mute (have to update button labels ourselves)
function ytMuteToggle(rm) {
   var im = rm.callAS("isMuted");
   if (im) {
       event.target.buttonSetCaption("\ytStrMUTE");
       rm.callAS("unMute");
   } else {
       event.target.buttonSetCaption("\ytStrUNMUTE");
       rm.callAS("mute");
   }
}
// Ask the user for the ID number of a new video, and play it
function ytSelect(rm,vID) {
   var rsp = app.response({
       cQuestion: "\ytRespQues",
       cTitle: "\ytRespTitle",
       cDefault: vID,
       cLabel: "\ytRespLabel"});
   if (rsp !=null && rsp != "")
       aebStartPlayer(rm,rsp,true); // dps
}
// open the video's YouTube page in the web browser
function ytOpenWeb(rm) {
   var link = rm.callAS("getVideoUrl");
   if (link != null) {
       app.launchURL(link,true);
       rm.activated = false;
   }
}
// rewind (seek to zero)
function ytRewind(rm) { rm.callAS("seekTo",0); }
/*
   ************************************************************
   Functions called by the player itself, in response to events
   as the events are "external", the annot is not the target.
   These functions must exist and match the names in the SWF.
   ***********************************************************
*/
function ytPlayerReady() {

   // this is the place to load your default video - for example...
   console.println("<YT> Player loaded and ready");
   //  this.getAnnotsRichMedia(this.pageNum)[0].callAS("loadVideoById",
   // "eNzrn8-JFSE",0);
   aebStartPlayer.isPlayerReady=true; // dps
}
function ytStateChange(st) {
   // Possible values are unstarted (-1), ended (0), playing (1),
   // paused (2), buffering (3), video cued (5)
   var lbl = "";
   console.println("<YT> State changed to " + st);
   if (st == 0) lbl = "\ytStrREPLAY";
   else if (st == 1) lbl = "\ytStrPAUSE";
   else if (st == 3) lbl = "\ytStrBuffering";
   else if (st == 2 || st == 5) lbl = "\ytStrPLAY";
   if (lbl) this.getField("playToggle").buttonSetCaption(lbl);
}
function ytPlaybackQualityChange(str) {
   // Possible values are "small", "medium", "large" and "hd720"
   console.println("<YT> Quality changed to " + str);
}
function ytProgress(q) {
 // q has four properties that you can use to update form fields,
 // such as...
 //this.getField("currentTime").value = q.CurrentTime;
 //this.getField("Duration").value = q.Duration;
 //this.getField("BytesLoaded").value = q.BytesLoaded;
 //this.getField("BytesTotal").value = q.BytesTotal;
}
function ytError(err) {
   // Video cannot be played
   console.println("<YT> ERROR code " + err + " received");
   if (err == 100)
       app.alert("\ytStrErrorVideoNotFound", 0, 0, "YouTube");
   else {
       var resp=app.alert("\ytStrErrorNoEmbed", 1, 3, "YouTube");
       if (resp==4) {
           aebCancelWait(false);
           ytOpenWeb(aebStartPlayer.annot);
       }
   }
}
/*
   We start the player if the annot is activated, if not,
   we set annot.activated=true, and wait for the widget to say it
   is ready. When ready, ytPlayerReady() sets
   aebStartPlayer.isPlayerReady=true
*/
function aebStartPlayer(rm,Id,bPlay) {
   aebStartPlayer.annot=rm;
   if (aebStartPlayer.annot.activated)
       aebStartPlayer.annot.callAS(%
(bPlay)?"loadVideoById":"cueVideoById",Id,0);
   else {
       aebCancelWait(false);
       aebStartPlayer.annot.activated=true;
       aebStartPlayer.isPlayerReady=false;
       aebStartPlayer.twait=app.setInterval(%
'aebWait4Ready(\"'+Id+'\",'+bPlay+');',250);
       aebStartPlayer.to=app.setTimeOut("aebCancelWait(true)", 10000);
   }
}
aebStartPlayer.isPlayerReady=false;
aebStartPlayer.twait=null;
aebStartPlayer.to=null;
/*
   If the player is ready, we start the video, and clear
   the setInterval, otherwise, we wait.
*/
function aebWait4Ready(Id,bPlay) {
   if (aebStartPlayer.isPlayerReady) {
       aebCancelWait(false);
       aebStartPlayer.annot.callAS(%
(bPlay)?"loadVideoById":"cueVideoById",Id,0);
   }
}
function aebCancelWait(bNotify) {
       var twait=aebStartPlayer.twait;
       if (aebStartPlayer.to!=null)
           try { app.clearTimeOut(aebStartPlayer.to); } catch(e) {};
       aebStartPlayer.to=null;
       if (aebStartPlayer.twait!=null)
           try { app.clearInterval(aebStartPlayer.twait); } catch(e) {}
       aebStartPlayer.twait=null;
       if ( bNotify && twait!=null ) app.alert("\ytStrConnecTimedOut");
}
\end{newsegment}
\begin{newsegment}{Popup Menu Data and JS}
\ytPopupData
var aChoice;
function ytProcessMenu(aMenu) {
   var cChoice = \popUpMenu(aMenu);
   if ( cChoice != null ) {
       aChoice=eval(cChoice);
       if (aChoice[1]=="") return null;
       var thisChoice=aChoice[0];
       if (ytProcessMenu.nChoice==undefined) {
           ytProcessMenu.nChoice=thisChoice;
           eval("aMenu"+ytProcessMenu.nChoice).bMarked=true;
       } else {
           eval("aMenu"+ytProcessMenu.nChoice).bMarked=false;
           var oldnChoice=ytProcessMenu.nChoice;
           ytProcessMenu.nChoice=thisChoice;
           eval("aMenu"+ytProcessMenu.nChoice).bMarked=(oldnChoice==ytProcessMenu.nChoice)?false:true;
       }
       return aChoice;
   } else return null;
}
function ytPopupMenu(rmaName,ytmenu) {
   var aChoice=ytProcessMenu(ytmenu);
   var rm=this.getAnnotRichMedia(this.pageNum,rmaName);
   if (aChoice!=null) {
       if (ytProcessMenu.lastDescrip==undefined) {
           aebStartPlayer(rm,aChoice[1],!event.shift);
       } else {
           if (ytProcessMenu.lastDescrip!=aChoice[1]) {
               aebStartPlayer(rm,aChoice[1],!event.shift);
           }
       }
       ytProcessMenu.lastDescrip=aChoice[1];
   }
}
\end{newsegment}
\end{insDLJS*}
\endinput
%%
%% End of file `yt4pdf.sty'.