ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
241 function getMp3PlayerHtml($a_preview = false)
242 {
243 global $tpl, $lng;
244
245 include_once("./Services/YUI/classes/class.ilYuiUtil.php");
247
248 $tpl->addJavascript("./Services/MediaObjects/js/MediaObjects.js");
249
250 if (!self::$lightbox_initialized && $a_preview)
251 {
252 include_once("./Services/UIComponent/Lightbox/classes/class.ilLightboxGUI.php");
253 $lb = new ilLightboxGUI("media_lightbox");
254 $lb->setWidth("660px");
255 $lb->addLightbox();
256 self::$lightbox_initialized = true;
257 }
258
259 require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
260 include_once("./Services/MediaObjects/classes/class.ilExternalMediaAnalyzer.php");
261
262 // youtube
264 {
266 /*
267 $html = '<object width="320" height="240">'.
268 '<param name="movie" value="http://www.youtube.com/v/'.$p["v"].'?fs=1">'.
269 '</param><param name="allowFullScreen" value="true"></param>'.
270 '<param name="allowscriptaccess" value="always">'.
271 '</param><embed src="http://www.youtube.com/v/'.$p["v"].'?fs=1" '.
272 'type="application/x-shockwave-flash" allowscriptaccess="always" '.
273 'allowfullscreen="true" width="320" height="240"></embed></object>';
274 return $html;*/
275 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
276 if ($a_preview)
277 {
278 if ($this->getDownloadLink() != "")
279 {
280 $mp_tpl->setCurrentBlock("ytdownload");
281 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
282 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
283 $mp_tpl->parseCurrentBlock();
284 }
285
286 $mp_tpl->setCurrentBlock("ytpreview");
287 if ($this->getVideoPreviewPic() != "")
288 {
289 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
290 }
291 else
292 {
293 $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
294 }
295 $height = $this->getDisplayHeight();
296 $width = $this->getDisplayWidth();
297 $mp_tpl->setVariable("DISPLAY_HEIGHT", $height);
298 $mp_tpl->setVariable("DISPLAY_WIDTH", $width);
299 $mp_tpl->setVariable("IMG_ALT", $this->video_preview_pic_alt);
300 $mp_tpl->setVariable("PTITLE", $this->getTitle());
301 $mp_tpl->parseCurrentBlock();
302 }
303 $mp_tpl->setCurrentBlock("youtube");
304 if ($a_preview)
305 {
306 $mp_tpl->setVariable("CLASS", "ilNoDisplay");
307 }
308 $mp_tpl->setVariable("PV", $p["v"]);
309 $mp_tpl->setVariable("PLAYER_NR", $this->id."_".$this->current_nr);
310 $mp_tpl->setVariable("TITLE", $this->getTitle());
311 $mp_tpl->setVariable("DESCRIPTION", $this->getDescription());
312 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
313 if ($a_preview)
314 {
315 $mp_tpl->setVariable("CLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
316 }
317 $mp_tpl->parseCurrentBlock();
318 return $mp_tpl->get();
319 }
320
321 // vimeo
323 {
325
326 $html = '<iframe src="http://player.vimeo.com/video/'.$p["id"].'" width="320" height="240" '.
327 'frameborder="0"></iframe>';
328
329 return $html;
330 }
331
332 $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
333 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
334
335 // video tag
336 if (in_array($mimeType, array("video/mp4", "video/m4v", "video/rtmp",
337 "video/x-flv", "video/webm", "video/youtube", "video/vimeo", "video/ogg")))
338 {
340
341 if ($mimeType == "video/quicktime")
342 {
343 $mimeType = "video/mov";
344 }
345
346 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
347
348 // preview
349 if ($a_preview)
350 {
351 if ($this->getDownloadLink() != "")
352 {
353 $mp_tpl->setCurrentBlock("download");
354 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
355 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
356 $mp_tpl->parseCurrentBlock();
357 }
358
359 $mp_tpl->setCurrentBlock("preview");
360 if ($this->getVideoPreviewPic() != "")
361 {
362 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
363 }
364 else
365 {
366 $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
367 }
368 $mp_tpl->setVariable("IMG_ALT", $this->video_preview_pic_alt);
369 $mp_tpl->setVariable("PTITLE", $this->getTitle());
370 $mp_tpl->parseCurrentBlock();
371 }
372
373 // sources
374 $mp_tpl->setCurrentBlock("source");
375 $mp_tpl->setVariable("FILE", $this->getFile());
376 $mp_tpl->setVariable("MIME", $mimeType);
377 $mp_tpl->parseCurrentBlock();
378
379 if (in_array($this->getAlternativeVideoMimeType(), array("video/mp4", "video/webm")))
380 {
381 $mp_tpl->setCurrentBlock("source");
382 $mp_tpl->setVariable("FILE", $this->getAlternativeVideoFile());
383 $mp_tpl->setVariable("MIME", $this->getAlternativeVideoMimeType());
384 $mp_tpl->parseCurrentBlock();
385 }
386
387 $mp_tpl->setCurrentBlock("mejs_video");
388
389 if ($a_preview)
390 {
391 $mp_tpl->setVariable("CLASS", "ilNoDisplay");
392 }
393
394 $mp_tpl->setVariable("PLAYER_NR", $this->id."_".$this->current_nr);
395 $mp_tpl->setVariable("EVENT_URL", $this->event_callback_url);
396 $height = $this->getDisplayHeight();
397 $width = $this->getDisplayWidth();
398 if (is_int(strpos($mimeType,"audio/mpeg")))
399 {
400 $height = "30";
401 }
402
403 $mp_tpl->setVariable("DISPLAY_HEIGHT", $height);
404 $mp_tpl->setVariable("DISPLAY_WIDTH", $width);
405 $mp_tpl->setVariable("PREVIEW_PIC", $this->getVideoPreviewPic());
406 $mp_tpl->setVariable("SWF_FILE", ilPlayerUtil::getFlashVideoPlayerFilename(true));
407 $mp_tpl->setVariable("FFILE", $this->getFile());
408 $mp_tpl->setVariable("TITLE", $this->getTitle());
409 $mp_tpl->setVariable("DESCRIPTION", $this->getDescription());
410 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
411 if ($a_preview)
412 {
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 {
420 $tpl->addOnLoadCode("new MediaElementPlayer('#player_".$this->id."_".$this->current_nr."');");
421 }
422
423//echo htmlentities($r); exit;
424 return $r;
425 }
426
427 // audio/mpeg
428 if (is_int(strpos($mimeType,"audio/mpeg")) ||
429 in_array($mimeType, array("application/ogg", "audio/ogg")))
430 {
432 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
433 $preview_output = false;
434 if ($this->getVideoPreviewPic() != "" || $this->getForceAudioPreview())
435 {
436 if ($this->getDownloadLink() != "")
437 {
438 $mp_tpl->setCurrentBlock("adownload");
439 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
440 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
441 $mp_tpl->parseCurrentBlock();
442 }
443
444 $mp_tpl->setCurrentBlock("apreview");
445 if ($this->getVideoPreviewPic() != "")
446 {
447 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
448 }
449 else
450 {
451 $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
452 }
453 $mp_tpl->setVariable("PTITLE", $this->getTitle());
454 $mp_tpl->parseCurrentBlock();
455 $preview_output = true;
456 }
457 $mp_tpl->setCurrentBlock("audio");
458 if ($preview_output)
459 {
460 $mp_tpl->setVariable("ASTYLE", "margin-top:-30px");
461 }
462 $mp_tpl->setVariable("AFILE", $this->getFile());
463 $mp_tpl->setVariable("APLAYER_NR", $this->id."_".$this->current_nr);
464 $mp_tpl->setVariable("AEVENT_URL", $this->event_callback_url);
465 $mp_tpl->setVariable("AHEIGHT", "30");
466 $mp_tpl->setVariable("AWIDTH", "320");
467 $mp_tpl->parseCurrentBlock();
468 return $mp_tpl->get();
469 }
470
471 // images
472 if (is_int(strpos($mimeType,"image/")))
473 {
474 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
475
476 if ($this->getDownloadLink() != "")
477 {
478 $mp_tpl->setCurrentBlock("idownload");
479 $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
480 $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
481 $mp_tpl->parseCurrentBlock();
482 }
483
484 $mp_tpl->setCurrentBlock("ipreview");
485 if ($this->getVideoPreviewPic() != "")
486 {
487 $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
488 }
489 else
490 {
491 $mp_tpl->setVariable("IMG_SRC", $this->getFile());
492 }
493 $mp_tpl->setVariable("PTITLE", $this->getTitle());
494 $mp_tpl->parseCurrentBlock();
495
496 $mp_tpl->setCurrentBlock("image");
497 $mp_tpl->setVariable("IFILE", $this->getFile());
498 $mp_tpl->setVariable("IPLAYER_NR", $this->id."_".$this->current_nr);
499 $mp_tpl->setVariable("ITITLE", $this->getTitle());
500 $mp_tpl->setVariable("IDESCRIPTION", $this->getDescription());
501 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
502 $mp_tpl->setVariable("ICLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
503
504 if($this->event_callback_url)
505 {
506 $mp_tpl->setVariable("IMG_CALLBACK_URL", $this->event_callback_url);
507 $mp_tpl->setVariable("IMG_CALLBACK_PLAYER_NR", $this->id."_".$this->current_nr);
508 }
509
510 $mp_tpl->setVariable("IHEIGHT", $this->getDisplayHeight());
511 $mp_tpl->setVariable("IWIDTH", $this->getDisplayWidth());
512 $mp_tpl->parseCurrentBlock();
513
514 return $mp_tpl->get();
515 }
516
517 // fallback, no preview mode
518 $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
519 if (strpos($mimeType,"flv") === false
520 && strpos($mimeType,"audio/mpeg") === false
521 && strpos($mimeType,"image/png") === false
522 && strpos($mimeType,"image/gif") === false)
523 {
524
525 $html = '<embed src="'.$this->getFile().'" '.
526 'type="'.$mimeType.'" '.
527 'ShowControls="1" '.
528 'autoplay="false" autostart="false" '.
529 'width="320" height="240" scale="aspect" ></embed>';
530 return $html;
531 }
532
533return;
534 $tpl->addJavaScript("./Services/MediaObjects/flash_flv_player/swfobject.js");
535 $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
536 $mp_tpl->setCurrentBlock("default");
537 $mp_tpl->setVariable("FILE", urlencode($this->getFile()));
538 $mp_tpl->setVariable("PLAYER_NR", $this->current_nr);
539 $mp_tpl->setVariable("DISPLAY_HEIGHT", strpos($mimeType,"audio/mpeg") === false ? "240" : "20");
540 $mp_tpl->setVariable("DISPLAY_WIDTH", "320");
541 $mp_tpl->parseCurrentBlock();
542 return $mp_tpl->get();
543 }
544
550 function getPreviewHtml()
551 {
552 return $this->getMp3PlayerHtml(true);
553 }
554
561 {
562 return $this->getMp3PlayerHtml(false);
563 }
564
565}
566?>
global $tpl
Definition: ilias.php:8
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.
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:40