forked from njaber/moodle-mod_mplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.php
More file actions
882 lines (748 loc) · 31.5 KB
/
Copy pathrenderer.php
File metadata and controls
882 lines (748 loc) · 31.5 KB
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains a renderer for the assignment class
*
* @package mod_mplayer
* @category mod
* @copyright Mat Bury (1.9)
* @author Valery Fremaux <valery.fremaux@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/mod/mplayer/locallib.php');
/**
* A custom renderer class that extends the plugin_renderer_base and is used by the assign module.
*
* @package mod_mplayer
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_mplayer_renderer extends plugin_renderer_base {
/**
* @param objectref &$mplayer
*/
public function intro(&$mplayer) {
$str = '';
if (!empty($mplayer->intro)) {
$str .= '<div class="mplayer intro">';
$str .= format_text($mplayer->intro, $mplayer->introformat);
$str .= '</div>';
}
return $str;
}
/**
* Construct Javascript SWFObject embed code for <body> section of view.php
* Please note: some URLs append a '?'.time(); query to prevent browser caching
*
* @param objectref &$mplayer (mdl_mplayer DB record for current mplayer module instance)
* @return string
*/
public function print_body(&$mplayer) {
global $CFG;
// A nice small tiny library for detecting mobile devices.
require_once($CFG->dirroot.'/mod/mplayer/extralib/Mobile_Detect.php');
$detect = new Mobile_Detect;
$cm = get_coursemodule_from_instance('mplayer', $mplayer->id);
$context = context_module::instance($cm->id);
$mplayerbody = $this->get_device_based_mplayer($mplayer, $cm, $context, $detect);
return $mplayerbody;
}
/**
* prints the body of the player
* @param objectref &$mplayer the MPlayer instance
* @param objectref &$cm the associated course module
* @param objectref &$context the associated context
* @return a complete HTML string with all flow player code.
*/
public function get_device_based_mplayer(&$mplayer, &$cm, &$context) {
global $CFG;
$isplaylist = false;
if ($mplayer->technology == 'flowplayer') {
$detector = new Mobile_Detect();
if ($detector->isMobile() && $detector->isAndroid()) {
$mplayerbody = $this->flowplayer_body($mplayer, $cm, $context, 'flash');
} else {
$mplayerbody = $this->flowplayer_body($mplayer, $cm, $context, 'html5');
}
} else {
$mplayerbody = $this->jwplayer_body($mplayer, $cm, $context);
}
if (!empty($mplayer->notes)) {
$mplayerbody .= '<div class="mplayer-notes"><p>'.$mplayer->notes.'</p></div>';
}
return $mplayerbody;
}
/**
* prints the flowplayer effective body (html5)
*
* @param objectref &$mplayer the MPlayer instance
* @param objectref &$cm the associated course module object
* @param objectref &$context the context object for this module
* @param string $forcedtype when equals to 'flash' will force the flash engine to be used
* whatever the technical detection.
* return html string
*/
public function flowplayer_body(&$mplayer, &$cm, &$context, $forcedtype = '') {
global $CFG, $DB;
static $loaded = false;
$config = get_config('mplayer');
$isplaylist = false;
$playlisthtml = '';
$canloadsmil = false;
$js = '';
$cm = get_coursemodule_from_instance('mplayer', $mplayer->id);
$context = context_module::instance($cm->id);
// Protect playlist type after a technology switch.
if (!in_array($mplayer->playlist, array('dots', 'thumbs'))) {
$DB->set_field('mplayer', 'playlist', 'dots', array('id' => $mplayer->id));
}
if (!isset($config->default_native_fullscreen)) {
set_config('default_native_fullscreen', 'false', 'mplayer');
}
/*
* Check poster image or splash screen
* change get poster image in poster directory
*/
if (empty($mplayer->splashmode)) {
if ($posterurl = mplayer_get_file_url($mplayer, 'mplayerfiles', $context, '/posters/')) {
$js .= 'flp'.$mplayer->id.".set('poster', '$posterurl');\n";
}
} else {
if ($posterurl = mplayer_get_file_url($mplayer, 'mplayerfiles', $context, '/posters/')) {
$js .= 'flp'.$mplayer->id.".set('splash', '$posterurl');\n";
}
}
// Check and get the autoplay capability.
if ($mplayer->autostart == 'true') {
$js .= 'flp'.$mplayer->id.".set('autoplay', true);\n";
}
// Check and get the fullscreen capability.
if ($mplayer->fullscreen == 'true') {
$js .= 'flp'.$mplayer->id.".set('fullscreen', true);\n";
}
// Check and get the muted state.
// $muted = 'data-muted='.$mplayer->mute;
// Check and get the volume.
$js .= 'flp'.$mplayer->id.".set('volume', '".sprintf("%.2f", $mplayer->volume / 100)."');\n";
if ($mplayer->playlist == 'thumbs') {
$playlistsheet = 'thumbs_playlist';
$playlistclass = 'thumbs';
} else {
$playlistsheet = 'dots_playlist';
$playlistclass = 'dots';
}
$engine = ($forcedtype == 'flash') ? ' data-engine="flash" ' : ' data-engine="html5" ';
// Check and get the playlist.
$clips = $this->flowplayer_get_clips($mplayer, $context);
if (!empty($clips)) {
$js .= $this->flowplayer_build_playlist($mplayer, $clips);
}
$js .= $this->flowplayer_subtitles($mplayer);
$js .= $this->flowplayer_cuepoints($mplayer, $context);
$style = $this->flowplayer_build_style($mplayer);
// Load those once only.
$scriptloadfragment = $this->flowplayer_init_scripts($playlistsheet);
// Streaming related tag.
$rtmpdata = '';
if ($mplayer->type == 'rtmp' && $mplayer->streamer == 'wowza') {
/*
// Not resolved yet.
$canloadsmil = true;
$rtmpdata = 'data-rtmp="'.@$config->wowzaserver.@$config->wowzaapplication.'" ';
*/
$js .= 'flp'.$mplayer->id.".set('rtmp', '".@$config->wowzaserver.@$config->wowzaapplication."');\n";
}
// Master player DIV.
if (is_numeric($mplayer->height)) {
$mplayer->height .= 'px';
}
if (is_numeric($mplayer->width)) {
$mplayer->width .= 'px';
}
$mplayerbody = $scriptloadfragment."\n";
$mplayerbody .= '<div class="mplayer-cont embed-responsive '.$mplayer->playlist.'"
style="width:'.$mplayer->width.';height:'.$mplayer->height.'"
id="flp'.$mplayer->id.'">';
$mplayerbody .= $this->flowplayer_cue_panels($mplayer);
if ($mplayer->playlist) {
$mplayerbody .= $this->flowplayer_playlist_html($mplayer, $clips);
}
$mplayerbody .= '</div>'; // Master container.
$mplayerbody .= $this->flowplayer_completion($mplayer, $clips); // Completion container.
$mplayerbody .= '<script type="text/javascript">'."\n";
$mplayerbody .= 'flp'.$mplayer->id." = new FlowplayerConfig();\n";
$mplayerbody .= $js;
$mplayerbody .= 'flp'.$mplayer->id.'.render('.$mplayer->id.");\n";
$mplayerbody .= "</script>\n";
$mplayerbody .= '<style>'.$style."</style>\n";
if (debugging() && !empty($config->displaydebugcode)) {
$mplayerbody .= '<pre>'.htmlentities($mplayerbody).'</pre>';
}
// If can load smile.
if ($canloadsmil) {
// Untested.
$mplayerbody .= $this->flowplayer_load_smil($mplayer);
}
return $mplayerbody;
}
/**
* Get clip information from any possible source
*
* @param objectref &$mplayer
* @param object $context
* @return an array of arrays as source definitions per clip
*/
public function flowplayer_get_clips(&$mplayer, $context) {
// These are alternate playlist resolutions in case we are NOT using an XML formal playlist.
$clips = array();
if (debugging() && !empty($config->displaydebugcode)) {
echo "making $mplayer->type playlist";
}
switch ($mplayer->type) {
case 'xml':
case 'xmlrtmp': {
// The playlist file has been uploaded.
$cm = get_coursemodule_from_instance('mplayer', $mplayer->id);
$context = context_module::instance($cm->id);
if (($playlistfile = mplayer_get_file_location($mplayer, 'playlistfiles', $context, '/playlist/'))) {
$clips = mplayer_xml_playlist($mplayer, $playlistfile);
}
break;
}
case 'httpxml':
case 'httpxmlrtmp': {
/* The playlist file is obtained from an external URL and stored into a special filearea.
* this filearea is NOT backuped and reloaded each time the media is accessed.
* TODO : Possibly add a hold time of the playlist.
*
* In RTMP case, the play list should contain stream references
*/
mplayer_load_remote_file($mplayer->external);
$playlistfile = mplayer_get_file_location($mplayer, 'remoteplaylist', $context);
$clips = mplayer_xml_playlist($mplayer, $playlistfile);
break;
}
case 'rtmp':
case 'video': {
/* Video stores files into moodle filestore directly, with eventual thumbs
* In RTMP case sources can be :
* - local rtmp proxies stored into the local storage (.stm files)
*/
$clips = mplayer_get_clips_from_files($mplayer);
break;
}
case 'url': {
// In that case, one clip per URL. No alternate sources possible.
if (!empty($mplayer->external)) {
$sources = explode(';', $mplayer->external);
$ix = 0;
foreach ($sources as $source) {
$clip = new StdClass();
$clip->sources[] = $source;
$clips[$ix] = $clip;
$ix++;
}
}
break;
}
default:
return null;
}
return $clips;
}
/**
* Builds the js sequence for making clips and playlist from a $clips array.
* @param objectref &$mplayer
* @param array $clips
*/
public function flowplayer_build_playlist(&$mplayer, $clips) {
$js = '';
// One single clip. No playlist.
if (empty($clips)) {
return $js;
}
if (count($clips) == 1) {
foreach ($clips[0]->sources as $source) {
$type = mplayer_flowplayer_get_type($mplayer, $source);
$js .= 'source = new Source(\''.$type.'\', \''.$source.'\');'."\n";
$js .= 'flp'.$mplayer->id.'.setSource(source);'."\n";
}
} else {
// If multiple clips, we need make a playlist.
foreach ($clips as $clipix => $clip) {
$js .= 'clip = new Clip();'."\n";
foreach ($clip->sources as $source) {
$type = mplayer_flowplayer_get_type($mplayer, $source);
$js .= 'source = new Source(\''.$type.'\', \''.$source.'\');'."\n";
$js .= 'clip.addSource(source);'."\n";
}
$js .= 'flp'.$mplayer->id.'.addClip(clip);'."\n";
}
}
return $js;
}
/**
* Experimental
* @param objectref &$mplayer
*/
protected function flowplayer_load_smil(&$mplayer) {
global $CFG;
$str = '';
$str .= '<script type="text/javascript">'."\n";
$str .= 'var mplayerinstance = flowplayer(\'flowplayer_'.$mplayer->id.'\')'."\n";
$smilurl = $CFG->wwwroot.'/mod/mplayer/flowplayer6/flowplayer.smil-3.2.9.swf';
$str .= 'mplayerinstance.loadPlugin(\'smil\', \''.$smilurl.'\');'."\n";
$str .= '</script>'."\n\n";
return $str;
}
/**
* Builds all HTML output for playlist visible parts
* @param objectref &$mplayer
* @param array $clips
*/
public function flowplayer_playlist_html(&$mplayer, $clips) {
$cm = get_coursemodule_from_instance('mplayer', $mplayer->id);
$context = context_module::instance($cm->id);
$str = '';
if (empty($clips)) {
return $str;
}
$hgroups = '';
$str .= '<div class="fp-playlist">';
$i = 0;
foreach ($clips as $clip) {
$listitemcontent = '';
if (!empty($clip->thumb)) {
$listitemcontent = '<img src="'.$clip->thumb.'" />';
}
$cliplink = '<a href="'.$clip->sources[0].'"
alt="'.@$clip->title.'"
title="'.@$clip->title.'"
id="item'.$i.'">'.$listitemcontent.'</a>';
$str .= $cliplink;
$hgtitle = '<h1 class="fp-playlist-info">'.@$clip->title.'</h1>';
$hgroups .= ' <hgroup class="info'.$i.'">'.$hgtitle.'</hgroup>';
$i++;
}
$str .= '</div>';
$str .= '<div>';
$str .= $hgroups;
$str .= '</div>';
return $str;
}
/**
* Prints the completion widget
* @param object $mplayer the MPlayer instance
* @return string the completion HTML sequence and HTML representation.
*/
public function flowplayer_completion($mplayer, $clips) {
global $CFG;
$cm = get_coursemodule_from_instance('mplayer', $mplayer->id);
$context = context_module::instance($cm->id);
if (!isloggedin() || is_guest($context)) {
return;
}
$str = '<div class="mplayer-completion-container container-fluid">';
$str .= '<div class="row-fluid">';
if ($clipsnum = count($clips)) {
$width = 100 / $clipsnum - 1;
foreach (array_keys($clips) as $clipix) {
$str .= ' <div class="mplayer-completion"
id="mplayer-progress-'.$mplayer->id.'_'.$clipix.'"
title="'.@$clips[$clipix]->title.'"
style="width:'.$width.'%"></div>';
}
}
$str .= '</div>';
$str .= '</div>';
return $str;
}
/**
* Build the subtitles members.
* It accepts that files may adopt several syntax to
* be dispatched on clips and selected as for language:
*
* {n}_subtitlefilename.vtt
* {n}_subtitlefilename_{lang}.vtt
* subtitlefilename_{lang}.vtt
*
* are accepted, with n numeric addressing the playlist index (0 for current clip).
*
* @param object $mplayer the mplayer instance
* @return an HTML String with track element list
*/
public function flowplayer_subtitles($mplayer) {
global $CFG, $COURSE, $USER;
$cm = get_coursemodule_from_instance('mplayer', $mplayer->id);
$context = context_module::instance($cm->id);
$fs = get_file_storage();
$js = '';
$strm = get_string_manager();
$languages = $strm->get_list_of_languages();
$langs = implode('|', array_keys($languages));
if ($files = $fs->get_directory_files($context->id, 'mod_mplayer', 'mplayerfiles', 0, '/tracks/', true, false,
'filepath, filename')) {
while ($file = array_shift($files)) {
$filename = pathinfo($file->get_filename(), PATHINFO_FILENAME);
$filepath = $file->get_filepath();
if (preg_match("/_($langs)/", $filename, $matches)) {
$lang = $matches[1];
} else {
$lang = 'en';
}
if (preg_match('#^/tracks/(\d+)/#', $filepath, $matches)) {
$ix = $matches[1];
} else {
if (preg_match("/^(\d+)_/", $filename, $matches)) {
$ix = $matches[1];
} else {
$ix = 0;
}
}
if ($mplayer->langselection == 0) {
$expectedlang = $COURSE->lang;
} else if ($mplayer->langselection == 1) {
$expectedlang = $USER->lang;
} else if ($mplayer->langselection == 2) {
assert(1);
} else if ($mplayer->langselection == 2) {
$expectedlang = $mplayer->langforced;
}
if (!empty($mplayer->selectlanguage)) {
if (!empty($lang) && $expectedlang != $lang) {
continue;
}
}
$trackurl = moodle_url::make_pluginfile_url($context->id, 'mod_mplayer', 'mplayerfiles', 0, $file->get_filepath(),
$file->get_filename());
$subtitles[$lang][$ix] = $trackurl;
}
foreach ($subtitles as $lang => $arr) {
foreach ($arr as $ix => $trackurl) {
$langlabel = $languages[$lang];
if ($ix == 0) {
$js .= 'flp'.$mplayer->id.".setSubtitle('subtitles', '$trackurl', '$lang', '$langlabel', true)\n";
$js .= 'flp'.$mplayer->id.".addSubtitle(0, 'subtitles', '$trackurl', '$lang', '$langlabel', true)\n";
} else {
$js .= 'flp'.$mplayer->id.".addSubtitle($ix, 'subtitles', '$trackurl', '$lang', '$langlabel')\n";
}
}
}
}
return $js;
}
/**
* Get cue list definitions from mplayer configuration and prepare
* Cue point arrays and HTML output.
* @param object $mplayer the HTML5 MPlayer instance
* @param arrayref $datacuepointsarr An array of cue points to fill
*/
public function flowplayer_cuepoints(&$mplayer, $context) {
// First get cue files if any.
$fs = get_file_storage();
$order = 'filepath, filename';
$cuefiles = $fs->get_directory_files($context->id, 'mod_mplayer', 'mplayerfiles', 0, '/cues/', true, false, $order);
$cues = array();
if (!empty($cuefiles)) {
foreach ($cuefiles as $storedfile) {
$filepath = $storedfile->get_filepath();
$filename = $storedfile->get_filename();
if ($filepath == '/cues/') {
if (preg_match('/^(\d+)_/', $filename, $matches)) {
$ix = $matches[0];
} else {
$ix = 0;
}
} else if (preg_match('#/cues/(\d+)/#', $filepath, $matches)) {
$ix = $matches[1];
} else {
continue;
}
// Ignore all other files.
$cuelist = $storedfile->get_content();
$cuelist = preg_replace("/\r/", '', $cuelist); // Protect windows end lines.
$cuearr = explode("\n", $cuelist);
foreach ($cuearr as $c) {
$cues[] = $ix.'|'.$c;
}
}
}
$js = '';
if (!empty($cues)) {
$mplayer->_has_cues = true;
foreach ($cues as $cue) {
@list($ix, $time, $url, $cueout, $mandatory) = explode('|', trim($cue));
if (empty($time)) {
continue;
}
if (empty($mandatory)) {
$mandatory = 'optional';
}
// Guess a type from url.
$type = '';
if (preg_match('#\/mod/(.+?)/view#', $url, $matches)) {
$type = 'mod_'.$matches[1];
}
list($h, $m, $s) = explode(':', $time);
$sectime = $h * 3600 + $m * 60 + $s;
if ($ix == 0) {
$js .= 'flp'.$mplayer->id.".setCue('$sectime', '$url', '$cueout', '$type', '$mandatory');\n";
} else {
$js .= 'flp'.$mplayer->id.".addCue($ix, '$sectime', '$url', '$cueout', '$type', '$mandatory');\n";
}
}
}
return $js;
}
public function flowplayer_cue_panels($mplayer) {
$str = '';
if (empty($mplayer->_has_cues)) {
return $str;
}
$str .= '<div id="fp-cue-in-'.$mplayer->id.'" class="fp-cue-in-panel">';
$str .= '</div>';
$str .= '<div id="fp-cue-out-'.$mplayer->id.'" class="fp-cue-resume-panel">';
$str .= get_string('resumefromcue', 'mod_mplayer');
$str .= '</div>';
return $str;
}
/**
* this is to include once the complementary JS we need.
* NOTE : most of the js/css are now loaded via mplayer_require_js
* @param string $playlistsheet
*/
public function flowplayer_init_scripts($playlistsheet) {
global $CFG, $PAGE;
static $loaded = false;
$scriptloadfragment = '';
if (!$loaded) {
$flowplayerbasecssurl = new moodle_url('/mod/mplayer/flowplayer6/skin/minimalist.css');
$flowplayerplaylistcssurl = new moodle_url('/mod/mplayer/flowplayer6/'.$playlistsheet.'.css');
$flowplayercompletionjscodeurl = new moodle_url('/mod/mplayer/js/completion.js');
$flowplayerconfigjscodeurl = new moodle_url('/mod/mplayer/js/flowplayer.js');
if (isloggedin() && !is_guest($PAGE->context)) {
$scriptloadfragment .= '<script type="text/javascript" src="'.$flowplayerconfigjscodeurl.'"></script>';
$scriptloadfragment .= '<script type="text/javascript" src="'.$flowplayercompletionjscodeurl.'"></script>';
}
$scriptloadfragment .= '
<link rel="stylesheet" type="text/css" href="'.$flowplayerplaylistcssurl.'">
<link rel="stylesheet" type="text/css" href="'.$flowplayerbasecssurl.'">
';
$loaded = true;
}
return $scriptloadfragment;
}
/**
* Not used.
*/
public function flowplayer_flash_body() {
global $CFG;
$body = '
var _flowplayer = flowplayer("flowplayer", "'.$CFG->wwwroot.'/mod/mplayer/skins/'.$mplayer->skin.'", {
plugins: {
controls: {
url: "'.$CFG->wwwroot.'/mod/mplayer/flowplayer/flowplayer.swf",
// Customize the appearance make it have a lighter look.
buttonColor: "rgba(0, 0, 0, 0.9)",
buttonOverColor: "#000000",
backgroundColor: "#D7D7D7",
backgroundGradient: "medium",
sliderColor: "#FFFFFF",
sliderBorder: "1px solid #808080",
volumeSliderColor: "#FFFFFF",
volumeBorder: "1px solid #808080",
timeColor: "#000000",
durationColor: "#535353"
}
},
clip: {
autoPlay: true
},
playlist: ' . json_encode($this->playlist) . '
});
';
}
/**
* Builds the flowplayer class and style ruleset
* @param objectref &$mplayer
*/
public function flowplayer_build_style(&$mplayer) {
$style = '';
if ($mplayer->screencolor) {
$style .= '.flowplayer {background-color: #'.str_replace('#', '', $mplayer->screencolor).' !important;}';
}
if ($mplayer->backcolor) {
$style .= '.flowplayer .fp-controls {background-color: #'.str_replace('#', '', $mplayer->backcolor).' !important;}';
}
if ($mplayer->frontcolor) {
$style .= '.flowplayer .fp-progress, .flowplayer .fp-volumelevel {
background-color: #'.str_replace('#', '', $mplayer->frontcolor).' !important;
}';
}
if ($mplayer->lightcolor) {
$style .= '.flowplayer .fp-buffer {background-color: #'.str_replace('#', '', $mplayer->lightcolor).' !important;}';
$style .= '.flowplayer .fp-time .fp-elapsed, .flowplayer .fp-time .fp-duration, .flowplayer .fp-mute {
color: #'.str_replace('#', '', $mplayer->lightcolor).' !important;
}';
}
return $style;
}
/**
* Prints JW player body.
*
* @param objectref &$mplayer
* @param object $cm
* @param object $context
* @return string
*/
public function jwplayer_body(&$mplayer, $cm, $context) {
global $CFG, $COURSE;
$completioninfo = new completion_info($COURSE);
$listbar = $mplayer->playlist ? $mplayer->playlist : 'none';
$mute = $mplayer->mute ? 'true' : 'false';
if (1) {
switch ($mplayer->type) {
case 'video':
case 'sound': {
$urlarray = mplayer_get_file_url($mplayer, 'mplayerfiles', $context, '/medias/0/', true);
break;
}
case 'url': {
# $urlarray = explode(';', ' ;' . $mplayer->external);
$urlarray = explode(';', $mplayer->external);
break;
}
case 'youtube': {
$urlarray = explode(';', $mplayer->external);
break;
}
default:
$urlarray = array();
}
$playlistthumb = mplayer_get_file_url($mplayer, 'mplayerfiles', $context, '/thumbs/', true);
$this->playlist = array();
if (is_array($urlarray)) {
foreach ($urlarray as $index => $url) {
if ($index !== '' && $url) {
$playlistitem = new StdClass;
$playlistitem->file = $url;
$playlistitem->image = isset($playlistthumb[$index]) ? $playlistthumb[$index] : '';
$playlistitem->title = 'test';
$this->playlist[] = $playlistitem;
}
}
}
}
$jwbody = '<div id="jwplayer_'.$mplayer->id.'">'.get_string('loadingplayer', 'mplayer').'</div>';
$jwbody .= '<script type="text/javascript">
window.onload = function() {
jwplayer.key = "pZDZgizUElLVj2BEBWMBql9bbp9Bnckbg7qQxw==";
jwplayer("jwplayer_'.$mplayer->id.'").setup({
"file": "'.$urlarray[0].'",
"image": "'.mplayer_get_file_url($mplayer, 'mplayerfiles', $context, '/posters/').'",
"playlist": '.json_encode($this->playlist).',
"height": "'.$mplayer->height.'",
"width": "'.$mplayer->width.'",
"volume": "'.$mplayer->volume.'",
"mute": "'.$mute.'",
"autostart": "'.$mplayer->autostart.'",
"stretching": "'.$mplayer->stretching.'",
"listbar": {
"position": "'.$listbar.'",
"size": "'.$mplayer->playlistsize.'"
}
});
setup_player_completion("jwplayer_'.$mplayer->id.'", "'.$mplayer->id.'");
};
</script>';
if ($completioninfo->is_enabled($cm) && in_array($mplayer->technology, array('jw712', 'jw'))) {
$jwbody .= '<div class="mplayer-jw-completion-container">';
$jwbody .= $this->flowplayer_completion($mplayer, $this->playlist);
$jwbody .= '</div>';
}
return $jwbody;
}
/**
* Draws a responsive progress bar
* outside style of progress bar is driven by mplayer stylesheet,
* unless innerbar width.
* @see ajax/markmediacompletion.php
*
* @param int $progress
* @param int $progress2
*/
public function progressbar($progress, $progress2 = null) {
$str = '';
$str .= '<div class="mod-mplayer-progressbar">';
$str .= '<div class="mod-mplayer-progressbar-outer">';
$str .= '<div class="mod-mplayer-progressbar-inner" style="width:'.$progress.'%">';
$str .= '</div>';
if (!is_null($progress2)) {
$str .= '<div class="mod-mplayer-progressbar-inner2" style="width:'.$progress2.'%">';
$str .= '</div>';
}
$str .= '</div>';
$str .= '</div>';
return $str;
}
/**
* plays a soundcard
*
* @param reference $flashcard
* @param string $soundname the local name of the sound file. Should be wav or any playable sound format.
* @param string $autostart if 'true' the sound starts playing immediately
* @see mod_flashcard
* NOT USED YET
*/
public function play_sound(&$mplayer, $clipid, $autostart = 'false', $htmlname = '') {
global $CFG, $COURSE;
$strmissingsound = get_string('missingsound', 'mplayer');
$fs = get_file_storage();
// New way : probably no effective fieldids storage needed anymore.
$cm = get_coursemodule_from_instance('mplayer', $mplayer->id);
$context = context_module::instance($cm->id);
$contextid = $context->id;
$soundfiles = $fs->get_directory_files($context->id, 'mod_mplayer', $filearea, 0, '/media/');
if (empty($soundfiles)) {
$soundhtml = $this->output->pix_icon('notfound', '', 'mod_mplayer');
return $soundhtml;
}
$soundfile = array_pop($soundfiles);
$filename = $soundfile->get_filename();
$magic = rand(0, 100000);
if ($htmlname == '') {
$htmlname = "bell_{$magic}";
}
$soundfileurl = $CFG->wwwroot."/pluginfile.php/{$contextid}/mod_mplayer/{$filearea}/0/media/{$clipid}/{$filename}";
if (!preg_match('/\.mp3$/i', $filename)) {
$soundhtml = "<embed src=\"{$soundfileurl}\"
autostart=\"{$autostart}\"
hidden=\"false\"
id=\"{$htmlname}_player\"
height=\"20\"
width=\"200\" />";
$soundhtml .= "<a href=\"{$soundfileurl}\"
autostart=\"{$autostart}\"
hidden=\"false\"
id=\"{$htmlname}\"
height=\"20\"
width=\"200\" />";
} else {
$soundhtml = flashcard_mp3_dewplayer($flashcard, $soundfileurl, $htmlname);
}
return $soundhtml;
}
}