ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
80  function setAlternativeVideoMimeType($a_val)
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 () {
110  return $this->displayHeight;
111  }
112 
118  function setDisplayWidth($a_val)
119  {
120  $this->displayWidth = $a_val;
121  }
122 
128  function getDisplayWidth()
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 
233  function getDownloadLink()
234  {
235  return $this->download_link;
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
263 /* if (ilExternalMediaAnalyzer::isYouTube($this->getFile()))
264  {
265  $p = ilExternalMediaAnalyzer::extractYouTubeParameters($this->getFile());
266  $html = '<object width="320" height="240">'.
267  '<param name="movie" value="http://www.youtube.com/v/'.$p["v"].'?fs=1">'.
268  '</param><param name="allowFullScreen" value="true"></param>'.
269  '<param name="allowscriptaccess" value="always">'.
270  '</param><embed src="http://www.youtube.com/v/'.$p["v"].'?fs=1" '.
271  'type="application/x-shockwave-flash" allowscriptaccess="always" '.
272  'allowfullscreen="true" width="320" height="240"></embed></object>';
273  return $html;
274  }
275 
276  // vimeo
277  if (ilExternalMediaAnalyzer::isVimeo($this->getFile()))
278  {
279  $p = ilExternalMediaAnalyzer::extractVimeoParameters($this->getFile());
280 
281  $html = '<iframe src="http://player.vimeo.com/video/'.$p["id"].'" width="320" height="240" '.
282  'frameborder="0"></iframe>';
283 
284  return $html;
285  }
286 */
287  $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
288  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
289 
290  // video tag
291  if (in_array($mimeType, array("video/mp4", "video/m4v", "video/rtmp",
292  "video/x-flv", "video/webm", "video/youtube", "video/vimeo", "video/ogg")))
293  {
295 
296  if ($mimeType == "video/quicktime")
297  {
298  $mimeType = "video/mov";
299  }
300 
301  $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
302 
303  // preview
304  if ($a_preview)
305  {
306  if ($this->getDownloadLink() != "")
307  {
308  $mp_tpl->setCurrentBlock("download");
309  $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
310  $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
311  $mp_tpl->parseCurrentBlock();
312  }
313 
314  $mp_tpl->setCurrentBlock("preview");
315  if ($this->getVideoPreviewPic() != "")
316  {
317  $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
318  }
319  else
320  {
321  $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
322  }
323  $mp_tpl->setVariable("IMG_ALT", $this->video_preview_pic_alt);
324  $mp_tpl->setVariable("PTITLE", $this->getTitle());
325  $mp_tpl->parseCurrentBlock();
326  }
327 
328  // sources
329  $mp_tpl->setCurrentBlock("source");
330  $mp_tpl->setVariable("FILE", $this->getFile());
331  $mp_tpl->setVariable("MIME", $mimeType);
332  $mp_tpl->parseCurrentBlock();
333 
334  if (in_array($this->getAlternativeVideoMimeType(), array("video/mp4", "video/webm")))
335  {
336  $mp_tpl->setCurrentBlock("source");
337  $mp_tpl->setVariable("FILE", $this->getAlternativeVideoFile());
338  $mp_tpl->setVariable("MIME", $this->getAlternativeVideoMimeType());
339  $mp_tpl->parseCurrentBlock();
340  }
341 
342  $mp_tpl->setCurrentBlock("mejs_video");
343 
344  if ($a_preview)
345  {
346  $mp_tpl->setVariable("CLASS", "ilNoDisplay");
347  }
348 
349  $mp_tpl->setVariable("PLAYER_NR", $this->id."_".$this->current_nr);
350  $mp_tpl->setVariable("EVENT_URL", $this->event_callback_url);
351  $height = $this->getDisplayHeight();
352  $width = $this->getDisplayWidth();
353  if (is_int(strpos($mimeType,"audio/mpeg")))
354  {
355  $height = "30";
356  }
357 
358  $mp_tpl->setVariable("DISPLAY_HEIGHT", $height);
359  $mp_tpl->setVariable("DISPLAY_WIDTH", $width);
360  $mp_tpl->setVariable("PREVIEW_PIC", $this->getVideoPreviewPic());
361  $mp_tpl->setVariable("SWF_FILE", ilPlayerUtil::getFlashVideoPlayerFilename(true));
362  $mp_tpl->setVariable("FFILE", $this->getFile());
363  $mp_tpl->setVariable("TITLE", $this->getTitle());
364  $mp_tpl->setVariable("DESCRIPTION", $this->getDescription());
365  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
366  if ($a_preview)
367  {
368  $mp_tpl->setVariable("CLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
369  }
370  $mp_tpl->parseCurrentBlock();
371  $r = $mp_tpl->get();
372 
373  if (!$a_preview)
374  {
375  $tpl->addOnLoadCode("new MediaElementPlayer('#player_".$this->id."_".$this->current_nr."');");
376  }
377 
378 //echo htmlentities($r);
379  return $r;
380  }
381 
382  // audio/mpeg
383  if (is_int(strpos($mimeType,"audio/mpeg")) ||
384  in_array($mimeType, array("application/ogg", "audio/ogg")))
385  {
387  $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
388  $preview_output = false;
389  if ($this->getVideoPreviewPic() != "" || $this->getForceAudioPreview())
390  {
391  if ($this->getDownloadLink() != "")
392  {
393  $mp_tpl->setCurrentBlock("adownload");
394  $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
395  $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
396  $mp_tpl->parseCurrentBlock();
397  }
398 
399  $mp_tpl->setCurrentBlock("apreview");
400  if ($this->getVideoPreviewPic() != "")
401  {
402  $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
403  }
404  else
405  {
406  $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.svg"));
407  }
408  $mp_tpl->setVariable("PTITLE", $this->getTitle());
409  $mp_tpl->parseCurrentBlock();
410  $preview_output = true;
411  }
412  $mp_tpl->setCurrentBlock("audio");
413  if ($preview_output)
414  {
415  $mp_tpl->setVariable("ASTYLE", "margin-top:-30px");
416  }
417  $mp_tpl->setVariable("AFILE", $this->getFile());
418  $mp_tpl->setVariable("APLAYER_NR", $this->id."_".$this->current_nr);
419  $mp_tpl->setVariable("AEVENT_URL", $this->event_callback_url);
420  $mp_tpl->setVariable("AHEIGHT", "30");
421  $mp_tpl->setVariable("AWIDTH", "320");
422  $mp_tpl->parseCurrentBlock();
423  return $mp_tpl->get();
424  }
425 
426  // images
427  if (is_int(strpos($mimeType,"image/")))
428  {
429  $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
430 
431  if ($this->getDownloadLink() != "")
432  {
433  $mp_tpl->setCurrentBlock("idownload");
434  $mp_tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
435  $mp_tpl->setVariable("HREF_DOWNLOAD", $this->getDownloadLink());
436  $mp_tpl->parseCurrentBlock();
437  }
438 
439  $mp_tpl->setCurrentBlock("ipreview");
440  if ($this->getVideoPreviewPic() != "")
441  {
442  $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
443  }
444  else
445  {
446  $mp_tpl->setVariable("IMG_SRC", $this->getFile());
447  }
448  $mp_tpl->setVariable("PTITLE", $this->getTitle());
449  $mp_tpl->parseCurrentBlock();
450 
451  $mp_tpl->setCurrentBlock("image");
452  $mp_tpl->setVariable("IFILE", $this->getFile());
453  $mp_tpl->setVariable("IPLAYER_NR", $this->id."_".$this->current_nr);
454  $mp_tpl->setVariable("ITITLE", $this->getTitle());
455  $mp_tpl->setVariable("IDESCRIPTION", $this->getDescription());
456  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
457  $mp_tpl->setVariable("ICLOSE", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
458 
459  $height = $this->getDisplayHeight();
460  $width = $this->getDisplayWidth();
461 
462  $mp_tpl->setVariable("IHEIGHT", $height);
463  $mp_tpl->setVariable("IWIDTH", $width);
464  $mp_tpl->parseCurrentBlock();
465 
466  return $mp_tpl->get();
467  }
468 
469  // fallback, no preview mode
470  $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
471  if (strpos($mimeType,"flv") === false
472  && strpos($mimeType,"audio/mpeg") === false
473  && strpos($mimeType,"image/png") === false
474  && strpos($mimeType,"image/gif") === false)
475  {
476 
477  $html = '<embed src="'.$this->getFile().'" '.
478  'type="'.$mimeType.'" '.
479  'ShowControls="1" '.
480  'autoplay="false" autostart="false" '.
481  'width="320" height="240" scale="aspect" ></embed>';
482  return $html;
483  }
484 
485 return;
486  $tpl->addJavaScript("./Services/MediaObjects/flash_flv_player/swfobject.js");
487  $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
488  $mp_tpl->setCurrentBlock("default");
489  $mp_tpl->setVariable("FILE", urlencode($this->getFile()));
490  $mp_tpl->setVariable("PLAYER_NR", $this->current_nr);
491  $mp_tpl->setVariable("DISPLAY_HEIGHT", strpos($mimeType,"audio/mpeg") === false ? "240" : "20");
492  $mp_tpl->setVariable("DISPLAY_WIDTH", "320");
493  $mp_tpl->parseCurrentBlock();
494  return $mp_tpl->get();
495  }
496 
502  function getPreviewHtml()
503  {
504  return $this->getMp3PlayerHtml(true);
505  }
506 
513  {
514  return $this->getMp3PlayerHtml(false);
515  }
516 
517 }
518 ?>