ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
18  protected $tpl;
19 
23  protected $lng;
24 
25  protected $file;
26  protected $displayHeight = "480";
27  protected $displayWidth = "640";
28  protected $mimeType;
29  protected static $nr = 1;
30  protected static $lightbox_initialized = false;
31  protected $current_nr;
32  protected $title;
33  protected $description;
34  protected $event_callback_url = "";
35  protected $download_link = "";
36 
37  public function __construct($a_id = "", $a_event_callback_url = "")
38  {
39  global $DIC;
40 
41  $this->tpl = $DIC["tpl"];
42  $this->lng = $DIC->language();
43  $this->id = $a_id;
44  $this->event_callback_url = $a_event_callback_url;
45  $this->current_nr = self::$nr;
46  self::$nr++;
47  }
48 
54  public function setFile($a_file)
55  {
56  $this->file = $a_file;
57  }
58 
64  public function getFile()
65  {
66  return $this->file;
67  }
68 
74  public function setAlternativeVideoFile($a_val)
75  {
76  $this->alt_video_file = $a_val;
77  }
78 
84  public function getAlternativeVideoFile()
85  {
86  return $this->alt_video_file;
87  }
88 
94  public function setAlternativeVideoMimeType($a_val)
95  {
96  $this->alt_video_mime = $a_val;
97  }
98 
104  public function getAlternativeVideoMimeType()
105  {
106  return $this->alt_video_mime;
107  }
108 
114  public function setDisplayHeight($dHeight)
115  {
116  $this->displayHeight = $dHeight;
117  }
118 
124  public function getDisplayHeight()
125  {
126  return $this->displayHeight;
127  }
128 
134  public function setDisplayWidth($a_val)
135  {
136  $this->displayWidth = $a_val;
137  }
138 
144  public function getDisplayWidth()
145  {
146  return $this->displayWidth;
147  }
148 
149  public function setMimeType($value)
150  {
151  $this->mimeType = $value;
152  }
153 
159  public function setVideoPreviewPic($a_val, $a_alt = "")
160  {
161  $this->video_preview_pic = $a_val;
162  $this->video_preview_pic_alt = $a_alt;
163  }
164 
170  public function getVideoPreviewPic()
171  {
172  return $this->video_preview_pic;
173  }
174 
180  public function setTitle($a_val)
181  {
182  $this->title = $a_val;
183  }
184 
190  public function getTitle()
191  {
192  return $this->title;
193  }
194 
200  public function setDescription($a_val)
201  {
202  $this->description = $a_val;
203  }
204 
210  public function getDescription()
211  {
212  return $this->description;
213  }
214 
220  public function setForceAudioPreview($a_val)
221  {
222  $this->force_audio_preview = $a_val;
223  }
224 
230  public function getForceAudioPreview()
231  {
232  return $this->force_audio_preview;
233  }
234 
240  public function setDownloadLink($a_val)
241  {
242  $this->download_link = $a_val;
243  }
244 
250  public function getDownloadLink()
251  {
252  return $this->download_link;
253  }
254 
259  public static function initJavascript($a_tpl = null)
260  {
261  global $DIC;
262 
263  $tpl = $DIC["tpl"];
264 
265  if ($a_tpl == null) {
266  $a_tpl = $tpl;
267  }
268 
269  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
271 
272  $a_tpl->addJavascript("./Services/MediaObjects/js/MediaObjects.js");
273 
274  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
276  }
277 
278 
282  public function getMp3PlayerHtml($a_preview = false)
283  {
284  $tpl = $this->tpl;
285  $lng = $this->lng;
286 
287  self::initJavascript($tpl);
288 
289  if (!self::$lightbox_initialized && $a_preview) {
290  include_once("./Services/UIComponent/Lightbox/classes/class.ilLightboxGUI.php");
291  $lb = new ilLightboxGUI("media_lightbox");
292  $lb->setWidth("660px");
293  $lb->addLightbox();
294  self::$lightbox_initialized = true;
295  }
296 
297  require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
298  include_once("./Services/MediaObjects/classes/class.ilExternalMediaAnalyzer.php");
299 
300  // youtube
303  /*
304  $html = '<object width="320" height="240">'.
305  '<param name="movie" value="http://www.youtube.com/v/'.$p["v"].'?fs=1">'.
306  '</param><param name="allowFullScreen" value="true"></param>'.
307  '<param name="allowscriptaccess" value="always">'.
308  '</param><embed src="http://www.youtube.com/v/'.$p["v"].'?fs=1" '.
309  'type="application/x-shockwave-flash" allowscriptaccess="always" '.
310  'allowfullscreen="true" width="320" height="240"></embed></object>';
311  return $html;*/
312  $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
313  if ($a_preview) {
314  if ($this->getDownloadLink() != "") {
315  $mp_tpl->setCurrentBlock("ytdownload");
316  $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
317  $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
318  $mp_tpl->parseCurrentBlock();
319  }
320 
321  $mp_tpl->setCurrentBlock("ytpreview");
322  if ($this->getVideoPreviewPic() != "") {
323  $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
324  } else {
325  $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
326  }
327  $height = $this->getDisplayHeight();
328  $width = $this->getDisplayWidth();
329  $mp_tpl->setVariable("DISPLAY_HEIGHT", $height);
330  $mp_tpl->setVariable("DISPLAY_WIDTH", $width);
331  $mp_tpl->setVariable("IMG_ALT", $this->video_preview_pic_alt);
332  $mp_tpl->setVariable("PTITLE", $this->getTitle());
333  $mp_tpl->parseCurrentBlock();
334  }
335  $mp_tpl->setCurrentBlock("youtube");
336  if ($a_preview) {
337  $mp_tpl->setVariable("CLASS", "ilNoDisplay");
338  }
339  $mp_tpl->setVariable("PV", $p["v"]);
340  $mp_tpl->setVariable("PLAYER_NR", $this->id . "_" . $this->current_nr);
341  $mp_tpl->setVariable("TITLE", $this->getTitle());
342  $mp_tpl->setVariable("DESCRIPTION", $this->getDescription());
343  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
344  if ($a_preview) {
345  $mp_tpl->setVariable("CLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
346  }
347  $mp_tpl->parseCurrentBlock();
348  return $mp_tpl->get();
349  }
350 
351  // vimeo
354  $html = '<iframe src="//player.vimeo.com/video/' . $p["id"] . '" width="320" height="240" ' .
355  'frameborder="0"></iframe>';
356 
357  return $html;
358  }
359 
360  $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
361  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
362 
363  // video tag
364  if (in_array($mimeType, array("video/mp4", "video/m4v", "video/rtmp",
365  "video/x-flv", "video/webm", "video/youtube", "video/vimeo", "video/ogg"))) {
366  if ($mimeType == "video/quicktime") {
367  $mimeType = "video/mov";
368  }
369 
370  $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
371 
372  // preview
373  if ($a_preview) {
374  if ($this->getDownloadLink() != "") {
375  $mp_tpl->setCurrentBlock("download");
376  $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
377  $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
378  $mp_tpl->parseCurrentBlock();
379  }
380 
381  $mp_tpl->setCurrentBlock("preview");
382  if ($this->getVideoPreviewPic() != "") {
383  $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
384  } else {
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  $mp_tpl->setCurrentBlock("source");
400  $mp_tpl->setVariable("FILE", $this->getAlternativeVideoFile());
401  $mp_tpl->setVariable("MIME", $this->getAlternativeVideoMimeType());
402  $mp_tpl->parseCurrentBlock();
403  }
404 
405  $mp_tpl->setCurrentBlock("mejs_video");
406 
407  if ($a_preview) {
408  $mp_tpl->setVariable("CLASS", "ilNoDisplay");
409  }
410 
411  $mp_tpl->setVariable("PLAYER_NR", $this->id . "_" . $this->current_nr);
412  $mp_tpl->setVariable("EVENT_URL", $this->event_callback_url);
413  $height = $this->getDisplayHeight();
414  $width = $this->getDisplayWidth();
415  if (is_int(strpos($mimeType, "audio/mpeg"))) {
416  $height = "30";
417  }
418 
419  $mp_tpl->setVariable("DISPLAY_HEIGHT", $height);
420  $mp_tpl->setVariable("DISPLAY_WIDTH", $width);
421  $mp_tpl->setVariable("PREVIEW_PIC", $this->getVideoPreviewPic());
422  $mp_tpl->setVariable("SWF_FILE", ilPlayerUtil::getFlashVideoPlayerFilename(true));
423  $mp_tpl->setVariable("FFILE", $this->getFile());
424  $mp_tpl->setVariable("TITLE", $this->getTitle());
425  $mp_tpl->setVariable("DESCRIPTION", $this->getDescription());
426  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
427  if ($a_preview) {
428  $mp_tpl->setVariable("CLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
429  }
430  $mp_tpl->parseCurrentBlock();
431  $r = $mp_tpl->get();
432 
433  if (!$a_preview) {
434  $tpl->addOnLoadCode("new MediaElementPlayer('#player_" . $this->id . "_" . $this->current_nr . "');");
435  }
436 
437  //echo htmlentities($r); exit;
438  return $r;
439  }
440 
441  // audio/mpeg
442  if (is_int(strpos($mimeType, "audio/mpeg")) ||
443  in_array($mimeType, array("application/ogg", "audio/ogg"))) {
445  $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
446  $preview_output = false;
447  if ($this->getVideoPreviewPic() != "" || $this->getForceAudioPreview()) {
448  if ($this->getDownloadLink() != "") {
449  $mp_tpl->setCurrentBlock("adownload");
450  $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
451  $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
452  $mp_tpl->parseCurrentBlock();
453  }
454 
455  $mp_tpl->setCurrentBlock("apreview");
456  if ($this->getVideoPreviewPic() != "") {
457  $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
458  } else {
459  $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
460  }
461  $mp_tpl->setVariable("PTITLE", $this->getTitle());
462  $mp_tpl->parseCurrentBlock();
463  $preview_output = true;
464  }
465  $mp_tpl->setCurrentBlock("audio");
466  if ($preview_output) {
467  $mp_tpl->setVariable("ASTYLE", "margin-top:-30px");
468  }
469  $mp_tpl->setVariable("AFILE", $this->getFile());
470  $mp_tpl->setVariable("APLAYER_NR", $this->id . "_" . $this->current_nr);
471  $mp_tpl->setVariable("AEVENT_URL", $this->event_callback_url);
472  $mp_tpl->setVariable("AHEIGHT", "30");
473  $mp_tpl->setVariable("AWIDTH", "320");
474  $mp_tpl->parseCurrentBlock();
475  return $mp_tpl->get();
476  }
477 
478  // images
479  if (is_int(strpos($mimeType, "image/"))) {
480  $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
481 
482  if ($this->getDownloadLink() != "") {
483  $mp_tpl->setCurrentBlock("idownload");
484  $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
485  $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
486  $mp_tpl->parseCurrentBlock();
487  }
488 
489  $mp_tpl->setCurrentBlock("ipreview");
490  if ($this->getVideoPreviewPic() != "") {
491  $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
492  } else {
493  $mp_tpl->setVariable("IMG_SRC", $this->getFile());
494  }
495  $mp_tpl->setVariable("PTITLE", $this->getTitle());
496  $mp_tpl->parseCurrentBlock();
497 
498  $mp_tpl->setCurrentBlock("image");
499  $mp_tpl->setVariable("IFILE", $this->getFile());
500  $mp_tpl->setVariable("IPLAYER_NR", $this->id . "_" . $this->current_nr);
501  $mp_tpl->setVariable("ITITLE", $this->getTitle());
502  $mp_tpl->setVariable("IDESCRIPTION", $this->getDescription());
503  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
504  $mp_tpl->setVariable("ICLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
505 
506  if ($this->event_callback_url) {
507  $mp_tpl->setVariable("IMG_CALLBACK_URL", $this->event_callback_url);
508  $mp_tpl->setVariable("IMG_CALLBACK_PLAYER_NR", $this->id . "_" . $this->current_nr);
509  }
510 
511  $mp_tpl->setVariable("IHEIGHT", $this->getDisplayHeight());
512  $mp_tpl->setVariable("IWIDTH", $this->getDisplayWidth());
513  $mp_tpl->parseCurrentBlock();
514 
515  return $mp_tpl->get();
516  }
517 
518  // fallback, no preview mode
519  $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
520  if (strpos($mimeType, "flv") === false
521  && strpos($mimeType, "audio/mpeg") === false
522  && strpos($mimeType, "image/png") === false
523  && strpos($mimeType, "image/gif") === false) {
524  $html = '<embed src="' . $this->getFile() . '" ' .
525  'type="' . $mimeType . '" ' .
526  'ShowControls="1" ' .
527  'autoplay="false" autostart="false" ' .
528  'width="320" height="240" scale="aspect" ></embed>';
529  return $html;
530  }
531 
532  return;
533  $tpl->addJavaScript("./Services/MediaObjects/flash_flv_player/swfobject.js");
534  $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
535  $mp_tpl->setCurrentBlock("default");
536  $mp_tpl->setVariable("FILE", urlencode($this->getFile()));
537  $mp_tpl->setVariable("PLAYER_NR", $this->current_nr);
538  $mp_tpl->setVariable("DISPLAY_HEIGHT", strpos($mimeType, "audio/mpeg") === false ? "240" : "20");
539  $mp_tpl->setVariable("DISPLAY_WIDTH", "320");
540  $mp_tpl->parseCurrentBlock();
541  return $mp_tpl->get();
542  }
543 
549  public function getPreviewHtml()
550  {
551  return $this->getMp3PlayerHtml(true);
552  }
553 
559  public function getMediaPlayerHtml()
560  {
561  return $this->getMp3PlayerHtml(false);
562  }
563 }
setTitle($a_val)
Set Title.
setDisplayHeight($dHeight)
set display height
setAlternativeVideoFile($a_val)
Set alternative video file.
setForceAudioPreview($a_val)
Set force audio preview.
static getMimeType($a_file, $a_external=null)
get mime type for file
getVideoPreviewPic()
Get video preview picture.
static isYouTube($a_location)
Identify YouTube links.
getDisplayHeight()
return display height of player.
setDescription($a_val)
Set description.
getPreviewHtml()
Get preview html.
getDescription()
Get description.
global $DIC
Definition: saml.php:7
setFile($a_file)
Set File.
getDownloadLink()
Get download link.
static initConnection(ilTemplate $a_main_tpl=null)
Init YUI Connection module.
static initJavascript($a_tpl=null)
Init Javascript.
static getFlashVideoPlayerFilename($a_fullpath=false)
Get flash video player file name.
static get($a_glyph, $a_text="")
Get glyph html.
Lighbox handling.
setDownloadLink($a_val)
Set download link.
getMediaPlayerHtml()
Get HTML (no preview) for media player integration.
getAlternativeVideoMimeType()
Get alternative video mime type.
getMp3PlayerHtml($a_preview=false)
Get Html for MP3 Player.
setDisplayWidth($a_val)
Set display width.
$r
Definition: example_031.php:79
getAlternativeVideoFile()
Get alternative video file.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
setAlternativeVideoMimeType($a_val)
Set alternative video mime type.
static initMediaElementJs($a_tpl=null)
Init mediaelement.js scripts.
__construct($a_id="", $a_event_callback_url="")
static extractVimeoParameters($a_location)
Extract Vimeo Parameter.
Reload workbook from saved file
Create styles array
The data for the language used.
static isVimeo($a_location)
Identify Vimeo links.
static extractYouTubeParameters($a_location)
Extract YouTube Parameter.
setVideoPreviewPic($a_val, $a_alt="")
Set video preview picture.
User interface for media player.
getDisplayWidth()
Get display width.
getForceAudioPreview()
Get force audio preview.
$html
Definition: example_001.php:87