ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
14{
15 protected $file;
16 protected $displayHeight = "480";
17 protected $displayWidth = "640";
18 protected $mimeType;
19 protected static $nr = 1;
20 protected static $lightbox_initialized = false;
21 protected $current_nr;
22 protected $title;
23 protected $description;
24 protected $event_callback_url = "";
25 protected $download_link = "";
26
27 function __construct($a_id = "", $a_event_callback_url = "")
28 {
29 $this->id = $a_id;
30 $this->event_callback_url = $a_event_callback_url;
31 $this->current_nr = self::$nr;
32 self::$nr++;
33 }
34
40 function setFile($a_file)
41 {
42 $this->file = $a_file;
43 }
44
50 function getFile()
51 {
52 return $this->file;
53 }
54
60 function setAlternativeVideoFile($a_val)
61 {
62 $this->alt_video_file = $a_val;
63 }
64
71 {
72 return $this->alt_video_file;
73 }
74
81 {
82 $this->alt_video_mime = $a_val;
83 }
84
91 {
92 return $this->alt_video_mime;
93 }
94
100 function setDisplayHeight ($dHeight) {
101 $this->displayHeight = $dHeight;
102 }
103
109 function getDisplayHeight () {
111 }
112
118 function setDisplayWidth($a_val)
119 {
120 $this->displayWidth = $a_val;
121 }
122
129 {
130 return $this->displayWidth;
131 }
132
133 function setMimeType ($value) {
134 $this->mimeType = $value;
135 }
136
142 function setVideoPreviewPic($a_val, $a_alt = "")
143 {
144 $this->video_preview_pic = $a_val;
145 $this->video_preview_pic_alt = $a_alt;
146 }
147
154 {
155 return $this->video_preview_pic;
156 }
157
163 function setTitle($a_val)
164 {
165 $this->title = $a_val;
166 }
167
173 function getTitle()
174 {
175 return $this->title;
176 }
177
183 function setDescription($a_val)
184 {
185 $this->description = $a_val;
186 }
187
193 function getDescription()
194 {
195 return $this->description;
196 }
197
203 function setForceAudioPreview($a_val)
204 {
205 $this->force_audio_preview = $a_val;
206 }
207
214 {
215 return $this->force_audio_preview;
216 }
217
223 function setDownloadLink($a_val)
224 {
225 $this->download_link = $a_val;
226 }
227
234 {
236 }
237
242 public static function initJavascript($a_tpl = null)
243 {
244 global $tpl;
245
246 if ($a_tpl == null)
247 {
248 $a_tpl = $tpl;
249 }
250
251 include_once("./Services/YUI/classes/class.ilYuiUtil.php");
253
254 $a_tpl->addJavascript("./Services/MediaObjects/js/MediaObjects.js");
255
256 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
258 }
259
260
264 function getMp3PlayerHtml($a_preview = false)
265 {
266 global $tpl, $lng;
267
269
270 if (!self::$lightbox_initialized && $a_preview)
271 {
272 include_once("./Services/UIComponent/Lightbox/classes/class.ilLightboxGUI.php");
273 $lb = new ilLightboxGUI("media_lightbox");
274 $lb->setWidth("660px");
275 $lb->addLightbox();
276 self::$lightbox_initialized = true;
277 }
278
279 require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
280 include_once("./Services/MediaObjects/classes/class.ilExternalMediaAnalyzer.php");
281
282 // youtube
284 {
286 /*
287 $html = '<object width="320" height="240">'.
288 '<param name="movie" value="http://www.youtube.com/v/'.$p["v"].'?fs=1">'.
289 '</param><param name="allowFullScreen" value="true"></param>'.
290 '<param name="allowscriptaccess" value="always">'.
291 '</param><embed src="http://www.youtube.com/v/'.$p["v"].'?fs=1" '.
292 'type="application/x-shockwave-flash" allowscriptaccess="always" '.
293 'allowfullscreen="true" width="320" height="240"></embed></object>';
294 return $html;*/
295 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
296 if ($a_preview)
297 {
298 if ($this->getDownloadLink() != "")
299 {
300 $mp_tpl->setCurrentBlock("ytdownload");
301 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
302 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
303 $mp_tpl->parseCurrentBlock();
304 }
305
306 $mp_tpl->setCurrentBlock("ytpreview");
307 if ($this->getVideoPreviewPic() != "")
308 {
309 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
310 }
311 else
312 {
313 $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
314 }
315 $height = $this->getDisplayHeight();
316 $width = $this->getDisplayWidth();
317 $mp_tpl->setVariable("DISPLAY_HEIGHT", $height);
318 $mp_tpl->setVariable("DISPLAY_WIDTH", $width);
319 $mp_tpl->setVariable("IMG_ALT", $this->video_preview_pic_alt);
320 $mp_tpl->setVariable("PTITLE", $this->getTitle());
321 $mp_tpl->parseCurrentBlock();
322 }
323 $mp_tpl->setCurrentBlock("youtube");
324 if ($a_preview)
325 {
326 $mp_tpl->setVariable("CLASS", "ilNoDisplay");
327 }
328 $mp_tpl->setVariable("PV", $p["v"]);
329 $mp_tpl->setVariable("PLAYER_NR", $this->id."_".$this->current_nr);
330 $mp_tpl->setVariable("TITLE", $this->getTitle());
331 $mp_tpl->setVariable("DESCRIPTION", $this->getDescription());
332 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
333 if ($a_preview)
334 {
335 $mp_tpl->setVariable("CLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
336 }
337 $mp_tpl->parseCurrentBlock();
338 return $mp_tpl->get();
339 }
340
341 // vimeo
343 {
345
346 $html = '<iframe src="http://player.vimeo.com/video/'.$p["id"].'" width="320" height="240" '.
347 'frameborder="0"></iframe>';
348
349 return $html;
350 }
351
352 $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
353 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
354
355 // video tag
356 if (in_array($mimeType, array("video/mp4", "video/m4v", "video/rtmp",
357 "video/x-flv", "video/webm", "video/youtube", "video/vimeo", "video/ogg")))
358 {
359
360 if ($mimeType == "video/quicktime")
361 {
362 $mimeType = "video/mov";
363 }
364
365 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
366
367 // preview
368 if ($a_preview)
369 {
370 if ($this->getDownloadLink() != "")
371 {
372 $mp_tpl->setCurrentBlock("download");
373 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
374 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
375 $mp_tpl->parseCurrentBlock();
376 }
377
378 $mp_tpl->setCurrentBlock("preview");
379 if ($this->getVideoPreviewPic() != "")
380 {
381 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
382 }
383 else
384 {
385 $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
386 }
387 $mp_tpl->setVariable("IMG_ALT", $this->video_preview_pic_alt);
388 $mp_tpl->setVariable("PTITLE", $this->getTitle());
389 $mp_tpl->parseCurrentBlock();
390 }
391
392 // sources
393 $mp_tpl->setCurrentBlock("source");
394 $mp_tpl->setVariable("FILE", $this->getFile());
395 $mp_tpl->setVariable("MIME", $mimeType);
396 $mp_tpl->parseCurrentBlock();
397
398 if (in_array($this->getAlternativeVideoMimeType(), array("video/mp4", "video/webm")))
399 {
400 $mp_tpl->setCurrentBlock("source");
401 $mp_tpl->setVariable("FILE", $this->getAlternativeVideoFile());
402 $mp_tpl->setVariable("MIME", $this->getAlternativeVideoMimeType());
403 $mp_tpl->parseCurrentBlock();
404 }
405
406 $mp_tpl->setCurrentBlock("mejs_video");
407
408 if ($a_preview)
409 {
410 $mp_tpl->setVariable("CLASS", "ilNoDisplay");
411 }
412
413 $mp_tpl->setVariable("PLAYER_NR", $this->id."_".$this->current_nr);
414 $mp_tpl->setVariable("EVENT_URL", $this->event_callback_url);
415 $height = $this->getDisplayHeight();
416 $width = $this->getDisplayWidth();
417 if (is_int(strpos($mimeType,"audio/mpeg")))
418 {
419 $height = "30";
420 }
421
422 $mp_tpl->setVariable("DISPLAY_HEIGHT", $height);
423 $mp_tpl->setVariable("DISPLAY_WIDTH", $width);
424 $mp_tpl->setVariable("PREVIEW_PIC", $this->getVideoPreviewPic());
425 $mp_tpl->setVariable("SWF_FILE", ilPlayerUtil::getFlashVideoPlayerFilename(true));
426 $mp_tpl->setVariable("FFILE", $this->getFile());
427 $mp_tpl->setVariable("TITLE", $this->getTitle());
428 $mp_tpl->setVariable("DESCRIPTION", $this->getDescription());
429 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
430 if ($a_preview)
431 {
432 $mp_tpl->setVariable("CLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
433 }
434 $mp_tpl->parseCurrentBlock();
435 $r = $mp_tpl->get();
436
437 if (!$a_preview)
438 {
439 $tpl->addOnLoadCode("new MediaElementPlayer('#player_".$this->id."_".$this->current_nr."');");
440 }
441
442//echo htmlentities($r); exit;
443 return $r;
444 }
445
446 // audio/mpeg
447 if (is_int(strpos($mimeType,"audio/mpeg")) ||
448 in_array($mimeType, array("application/ogg", "audio/ogg")))
449 {
451 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
452 $preview_output = false;
453 if ($this->getVideoPreviewPic() != "" || $this->getForceAudioPreview())
454 {
455 if ($this->getDownloadLink() != "")
456 {
457 $mp_tpl->setCurrentBlock("adownload");
458 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
459 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
460 $mp_tpl->parseCurrentBlock();
461 }
462
463 $mp_tpl->setCurrentBlock("apreview");
464 if ($this->getVideoPreviewPic() != "")
465 {
466 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
467 }
468 else
469 {
470 $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
471 }
472 $mp_tpl->setVariable("PTITLE", $this->getTitle());
473 $mp_tpl->parseCurrentBlock();
474 $preview_output = true;
475 }
476 $mp_tpl->setCurrentBlock("audio");
477 if ($preview_output)
478 {
479 $mp_tpl->setVariable("ASTYLE", "margin-top:-30px");
480 }
481 $mp_tpl->setVariable("AFILE", $this->getFile());
482 $mp_tpl->setVariable("APLAYER_NR", $this->id."_".$this->current_nr);
483 $mp_tpl->setVariable("AEVENT_URL", $this->event_callback_url);
484 $mp_tpl->setVariable("AHEIGHT", "30");
485 $mp_tpl->setVariable("AWIDTH", "320");
486 $mp_tpl->parseCurrentBlock();
487 return $mp_tpl->get();
488 }
489
490 // images
491 if (is_int(strpos($mimeType,"image/")))
492 {
493 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
494
495 if ($this->getDownloadLink() != "")
496 {
497 $mp_tpl->setCurrentBlock("idownload");
498 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
499 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
500 $mp_tpl->parseCurrentBlock();
501 }
502
503 $mp_tpl->setCurrentBlock("ipreview");
504 if ($this->getVideoPreviewPic() != "")
505 {
506 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
507 }
508 else
509 {
510 $mp_tpl->setVariable("IMG_SRC", $this->getFile());
511 }
512 $mp_tpl->setVariable("PTITLE", $this->getTitle());
513 $mp_tpl->parseCurrentBlock();
514
515 $mp_tpl->setCurrentBlock("image");
516 $mp_tpl->setVariable("IFILE", $this->getFile());
517 $mp_tpl->setVariable("IPLAYER_NR", $this->id."_".$this->current_nr);
518 $mp_tpl->setVariable("ITITLE", $this->getTitle());
519 $mp_tpl->setVariable("IDESCRIPTION", $this->getDescription());
520 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
521 $mp_tpl->setVariable("ICLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
522
523 if($this->event_callback_url)
524 {
525 $mp_tpl->setVariable("IMG_CALLBACK_URL", $this->event_callback_url);
526 $mp_tpl->setVariable("IMG_CALLBACK_PLAYER_NR", $this->id."_".$this->current_nr);
527 }
528
529 $mp_tpl->setVariable("IHEIGHT", $this->getDisplayHeight());
530 $mp_tpl->setVariable("IWIDTH", $this->getDisplayWidth());
531 $mp_tpl->parseCurrentBlock();
532
533 return $mp_tpl->get();
534 }
535
536 // fallback, no preview mode
537 $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
538 if (strpos($mimeType,"flv") === false
539 && strpos($mimeType,"audio/mpeg") === false
540 && strpos($mimeType,"image/png") === false
541 && strpos($mimeType,"image/gif") === false)
542 {
543
544 $html = '<embed src="'.$this->getFile().'" '.
545 'type="'.$mimeType.'" '.
546 'ShowControls="1" '.
547 'autoplay="false" autostart="false" '.
548 'width="320" height="240" scale="aspect" ></embed>';
549 return $html;
550 }
551
552return;
553 $tpl->addJavaScript("./Services/MediaObjects/flash_flv_player/swfobject.js");
554 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
555 $mp_tpl->setCurrentBlock("default");
556 $mp_tpl->setVariable("FILE", urlencode($this->getFile()));
557 $mp_tpl->setVariable("PLAYER_NR", $this->current_nr);
558 $mp_tpl->setVariable("DISPLAY_HEIGHT", strpos($mimeType,"audio/mpeg") === false ? "240" : "20");
559 $mp_tpl->setVariable("DISPLAY_WIDTH", "320");
560 $mp_tpl->parseCurrentBlock();
561 return $mp_tpl->get();
562 }
563
569 function getPreviewHtml()
570 {
571 return $this->getMp3PlayerHtml(true);
572 }
573
580 {
581 return $this->getMp3PlayerHtml(false);
582 }
583
584}
585?>
global $tpl
Definition: ilias.php:8
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=false)
get mime type for file
static getFlashVideoPlayerFilename($a_fullpath=false)
Get flash video player file name.
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()
Init YUI Connection module.
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79
global $lng
Definition: privfeed.php:17