summaryrefslogtreecommitdiff
path: root/obsolete/macros/latex/contrib/yt4pdf/yt4pdf.sty
blob: 7bed0d249980d5aa9635be56a1dbd25fe69195f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
%%
%% 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                      %%
%%   dpstory@uakron.edu                                 %%
%%                                                      %%
%% 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{\yt@rm.callAS("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'.