ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMediaPlayerGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2012 ILIAS open source, GPL, see docs/LICENSE */
4
12{
16 protected $tpl;
17
21 protected $lng;
22
23 protected $file;
24 protected $displayHeight = "";
25 protected $displayWidth = "";
26 protected $mimeType;
27 protected static $nr = 1;
28 protected static $lightbox_initialized = false;
29 protected $current_nr;
30 protected $title;
31 protected $description;
32 protected $event_callback_url = "";
33 protected $download_link = "";
34
35 public function __construct($a_id = "", $a_event_callback_url = "")
36 {
37 global $DIC;
38
39 $this->tpl = $DIC["tpl"];
40 $this->lng = $DIC->language();
41 $this->id = $a_id;
42 $this->event_callback_url = $a_event_callback_url;
43 $this->current_nr = self::$nr;
44 self::$nr++;
45 }
46
51 public function setFile($a_file)
52 {
53 $this->file = $a_file;
54 }
55
60 public function getFile()
61 {
62 return $this->file;
63 }
64
69 public function setAlternativeVideoFile($a_val)
70 {
71 $this->alt_video_file = $a_val;
72 }
73
78 public function getAlternativeVideoFile()
79 {
80 return $this->alt_video_file;
81 }
82
87 public function setAlternativeVideoMimeType($a_val)
88 {
89 $this->alt_video_mime = $a_val;
90 }
91
97 {
98 return $this->alt_video_mime;
99 }
100
105 public function setDisplayHeight($dHeight)
106 {
107 $this->displayHeight = $dHeight;
108 }
109
114 public function getDisplayHeight()
115 {
117 }
118
123 public function setDisplayWidth($a_val)
124 {
125 $this->displayWidth = $a_val;
126 }
127
132 public function getDisplayWidth()
133 {
134 return $this->displayWidth;
135 }
136
137 public function setMimeType($value)
138 {
139 $this->mimeType = $value;
140 }
141
146 public function setVideoPreviewPic($a_val, $a_alt = "")
147 {
148 $this->video_preview_pic = $a_val;
149 $this->video_preview_pic_alt = $a_alt;
150 }
151
156 public function getVideoPreviewPic()
157 {
158 return $this->video_preview_pic;
159 }
160
165 public function setTitle($a_val)
166 {
167 $this->title = $a_val;
168 }
169
174 public function getTitle()
175 {
176 return $this->title;
177 }
178
183 public function setDescription($a_val)
184 {
185 $this->description = $a_val;
186 }
187
192 public function getDescription()
193 {
194 return $this->description;
195 }
196
201 public function setForceAudioPreview($a_val)
202 {
203 $this->force_audio_preview = $a_val;
204 }
205
210 public function getForceAudioPreview()
211 {
212 return $this->force_audio_preview;
213 }
214
219 public function setDownloadLink($a_val)
220 {
221 $this->download_link = $a_val;
222 }
223
228 public function getDownloadLink()
229 {
231 }
232
237 public static function initJavascript($a_tpl = null)
238 {
239 global $DIC;
240
241 $tpl = $DIC["tpl"];
242
243 if ($a_tpl == null) {
244 $a_tpl = $tpl;
245 }
246
247 include_once("./Services/YUI/classes/class.ilYuiUtil.php");
249
250 $a_tpl->addJavascript("./Services/MediaObjects/js/MediaObjects.js?1");
251
252 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
254 }
255
259 public function getMp3PlayerHtml($a_preview = false)
260 {
263
265
266 if (!self::$lightbox_initialized && $a_preview) {
267 include_once("./Services/UIComponent/Lightbox/classes/class.ilLightboxGUI.php");
268 $lb = new ilLightboxGUI("media_lightbox");
269 $lb->setWidth("660px");
270 $lb->addLightbox();
271 self::$lightbox_initialized = true;
272 }
273
274 require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
275 include_once("./Services/MediaObjects/classes/class.ilExternalMediaAnalyzer.php");
276
277 // youtube
280 /*
281 $html = '<object width="320" height="240">'.
282 '<param name="movie" value="http://www.youtube.com/v/'.$p["v"].'?fs=1">'.
283 '</param><param name="allowFullScreen" value="true"></param>'.
284 '<param name="allowscriptaccess" value="always">'.
285 '</param><embed src="http://www.youtube.com/v/'.$p["v"].'?fs=1" '.
286 'type="application/x-shockwave-flash" allowscriptaccess="always" '.
287 'allowfullscreen="true" width="320" height="240"></embed></object>';
288 return $html;*/
289 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
290 if ($a_preview) {
291 if ($this->getDownloadLink() != "") {
292 $mp_tpl->setCurrentBlock("ytdownload");
293 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
294 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
295 $mp_tpl->parseCurrentBlock();
296 }
297
298 $mp_tpl->setCurrentBlock("ytpreview");
299 if ($this->getVideoPreviewPic() != "") {
300 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
301 } else {
302 $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
303 }
304 $height = $this->getDisplayHeight();
305 $width = $this->getDisplayWidth();
306 $mp_tpl->setVariable("DISPLAY_HEIGHT", $height);
307 $mp_tpl->setVariable("DISPLAY_WIDTH", $width);
308 $mp_tpl->setVariable("IMG_ALT", $this->video_preview_pic_alt);
309 $mp_tpl->setVariable("PTITLE", $this->getTitle());
310 $mp_tpl->parseCurrentBlock();
311 }
312 $mp_tpl->setCurrentBlock("youtube");
313 if ($a_preview) {
314 $mp_tpl->setVariable("CLASS", "ilNoDisplay");
315 }
316 $mp_tpl->setVariable("PV", $p["v"]);
317 $mp_tpl->setVariable("PLAYER_NR", $this->id . "_" . $this->current_nr);
318 $mp_tpl->setVariable("TXT_PLAY", $lng->txt("mob_play"));
319 $mp_tpl->setVariable("TITLE", $this->getTitle());
320 $mp_tpl->setVariable("DESCRIPTION", $this->getDescription());
321 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
322 if ($a_preview) {
323 $mp_tpl->setVariable("CLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
324 }
325 $mp_tpl->parseCurrentBlock();
326 return $mp_tpl->get();
327 }
328
329 // vimeo
332 $html = '<iframe src="//player.vimeo.com/video/' . $p["id"] . '" width="320" height="240" ' .
333 'frameborder="0"></iframe>';
334
335 return $html;
336 }
337
338 $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
339 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
340
341 // video tag
342 if (in_array($mimeType, array("video/mp4",
343 "video/m4v",
344 "video/rtmp",
345 "video/x-flv",
346 "video/webm",
347 "video/youtube",
348 "video/vimeo",
349 "video/ogg"
350 ))) {
351 if ($mimeType == "video/quicktime") {
352 $mimeType = "video/mov";
353 }
354
355 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
356
357 // preview
358 if ($a_preview) {
359 if ($this->getDownloadLink() != "") {
360 $mp_tpl->setCurrentBlock("download");
361 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
362 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
363 $mp_tpl->parseCurrentBlock();
364 }
365
366 $mp_tpl->setCurrentBlock("preview");
367 if ($this->getVideoPreviewPic() != "") {
368 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
369 } else {
370 $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
371 }
372 $mp_tpl->setVariable("IMG_ALT", $this->video_preview_pic_alt);
373 $mp_tpl->setVariable("PTITLE", $this->getTitle());
374 $mp_tpl->parseCurrentBlock();
375 }
376
377 $mp_tpl->setCurrentBlock("mejs_video");
378
379 if ($a_preview) {
380 $mp_tpl->setVariable("WRAP_CLASS", "ilNoDisplay");
381 $mp_tpl->setVariable("CLASS", "mejs__player ilNoDisplay");
382 } else {
383 //$mp_tpl->setVariable("CLASS", "mejs__player");
384 }
385
386 // sources
387 $mp_tpl->setVariable("FILE", $this->getFile());
388 $mp_tpl->setVariable("PLAYER_NR", $this->id . "_" . $this->current_nr);
389 $mp_tpl->setVariable("TXT_PLAY", $lng->txt("mob_play"));
390 $mp_tpl->setVariable("EVENT_URL", $this->event_callback_url);
391 $height = $this->getDisplayHeight();
392 $width = $this->getDisplayWidth();
393 if (is_int(strpos($mimeType, "audio/mpeg"))) {
394 //$height = "30px";
395 }
396
397 if ($height != "") {
398 $style = "height: " . $height . "; ";
399 }
400 if ($width != "") {
401 $style .= "width: " . $width . "; ";
402 }
403 if ($style != "") {
404 $mp_tpl->setVariable("STYLE", "style='$style'");
405 }
406 //$mp_tpl->setVariable("DISPLAY_HEIGHT", $height);
407 //$mp_tpl->setVariable("DISPLAY_WIDTH", $width);
408 $mp_tpl->setVariable("PREVIEW_PIC", $this->getVideoPreviewPic());
409 $mp_tpl->setVariable("TITLE", $this->getTitle());
410 $mp_tpl->setVariable("DESCRIPTION", $this->getDescription());
411 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
412 if ($a_preview) {
413 $mp_tpl->setVariable("CLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
414 }
415 $mp_tpl->parseCurrentBlock();
416 $r = $mp_tpl->get();
417
418 if (!$a_preview) {
419 $tpl->addOnLoadCode("new MediaElementPlayer('player_" . $this->id . "_" . $this->current_nr . "');");
420 }
421
422 //echo htmlentities($r); exit;
423 return $r;
424 }
425
426 // audio/mpeg
427 if (is_int(strpos($mimeType, "audio/mpeg")) ||
428 in_array($mimeType, array("application/ogg", "audio/ogg"))) {
430 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
431 $preview_output = false;
432 if ($this->getVideoPreviewPic() != "" || $this->getForceAudioPreview()) {
433 if ($this->getDownloadLink() != "") {
434 $mp_tpl->setCurrentBlock("adownload");
435 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
436 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
437 $mp_tpl->parseCurrentBlock();
438 }
439
440 $mp_tpl->setCurrentBlock("apreview");
441 if ($this->getVideoPreviewPic() != "") {
442 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
443 } else {
444 $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
445 }
446 $mp_tpl->setVariable("PTITLE", $this->getTitle());
447 $mp_tpl->parseCurrentBlock();
448 $preview_output = true;
449 }
450 $mp_tpl->setCurrentBlock("audio");
451 if ($preview_output) {
452 $mp_tpl->setVariable("ASTYLE", "margin-top:-40px");
453 }
454 $mp_tpl->setVariable("AFILE", $this->getFile());
455 $mp_tpl->setVariable("APLAYER_NR", $this->id . "_" . $this->current_nr);
456 $mp_tpl->setVariable("AEVENT_URL", $this->event_callback_url);
457 $mp_tpl->setVariable("AHEIGHT", "40");
458 $mp_tpl->setVariable("AWIDTH", "320");
459 $mp_tpl->parseCurrentBlock();
460 return $mp_tpl->get();
461 }
462
463 // images
464 if (is_int(strpos($mimeType, "image/"))) {
465 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
466
467 if ($this->getDownloadLink() != "") {
468 $mp_tpl->setCurrentBlock("idownload");
469 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
470 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
471 $mp_tpl->parseCurrentBlock();
472 }
473
474 $mp_tpl->setCurrentBlock("ipreview");
475 if ($this->getVideoPreviewPic() != "") {
476 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
477 } else {
478 $mp_tpl->setVariable("IMG_SRC", $this->getFile());
479 }
480 $mp_tpl->setVariable("PTITLE", $this->getTitle());
481 $mp_tpl->parseCurrentBlock();
482
483 $mp_tpl->setCurrentBlock("image");
484 $mp_tpl->setVariable("IFILE", $this->getFile());
485 $mp_tpl->setVariable("IPLAYER_NR", $this->id . "_" . $this->current_nr);
486 $mp_tpl->setVariable("ITITLE", $this->getTitle());
487 $mp_tpl->setVariable("IDESCRIPTION", $this->getDescription());
488 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
489 $mp_tpl->setVariable("ICLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
490
491 if ($this->event_callback_url) {
492 $mp_tpl->setVariable("IMG_CALLBACK_URL", $this->event_callback_url);
493 $mp_tpl->setVariable("IMG_CALLBACK_PLAYER_NR", $this->id . "_" . $this->current_nr);
494 }
495
496 $mp_tpl->setVariable("IHEIGHT", $this->getDisplayHeight());
497 $mp_tpl->setVariable("IWIDTH", $this->getDisplayWidth());
498 $mp_tpl->parseCurrentBlock();
499
500 return $mp_tpl->get();
501 }
502
503 // fallback, no preview mode
504 $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
505 if (strpos($mimeType, "flv") === false
506 && strpos($mimeType, "audio/mpeg") === false
507 && strpos($mimeType, "image/png") === false
508 && strpos($mimeType, "image/gif") === false) {
509 $html = '<embed src="' . $this->getFile() . '" ' .
510 'type="' . $mimeType . '" ' .
511 'ShowControls="1" ' .
512 'autoplay="false" autostart="false" ' .
513 'width="320" height="240" scale="aspect" ></embed>';
514 return $html;
515 }
516
517 return;
518 }
519
524 public function getPreviewHtml()
525 {
526 return $this->getMp3PlayerHtml(true);
527 }
528
533 public function getMediaPlayerHtml()
534 {
535 return $this->getMp3PlayerHtml(false);
536 }
537}
An exception for terminatinating execution or to throw for unit testing.
static extractYouTubeParameters($a_location)
Extract YouTube Parameter.
static isVimeo($a_location)
Identify Vimeo links.
static extractVimeoParameters($a_location)
Extract Vimeo Parameter.
static isYouTube($a_location)
Identify YouTube links.
static get($a_glyph, $a_text="")
Get glyph html.
Lighbox handling.
User interface for media player.
setDisplayWidth($a_val)
Set display width.
getForceAudioPreview()
Get force audio preview.
setDisplayHeight($dHeight)
set display height
getDisplayWidth()
Get display width.
static initJavascript($a_tpl=null)
Init Javascript.
getAlternativeVideoFile()
Get alternative video file.
setTitle($a_val)
Set Title.
setDescription($a_val)
Set description.
getPreviewHtml()
Get preview html.
getDescription()
Get description.
setVideoPreviewPic($a_val, $a_alt="")
Set video preview picture.
getMediaPlayerHtml()
Get HTML (no preview) for media player integration.
setFile($a_file)
Set File.
getAlternativeVideoMimeType()
Get alternative video mime type.
setDownloadLink($a_val)
Set download link.
__construct($a_id="", $a_event_callback_url="")
setAlternativeVideoFile($a_val)
Set alternative video file.
getVideoPreviewPic()
Get video preview picture.
setAlternativeVideoMimeType($a_val)
Set alternative video mime type.
getDisplayHeight()
return display height of player.
setForceAudioPreview($a_val)
Set force audio preview.
getMp3PlayerHtml($a_preview=false)
Get Html for MP3 Player.
getDownloadLink()
Get download link.
static getMimeType($a_file, $a_external=null)
get mime type for file
static initMediaElementJs($a_tpl=null)
Init mediaelement.js scripts.
special template class to simplify handling of ITX/PEAR
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static initConnection(ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Connection module.
global $DIC
Definition: goto.php:24