ILIAS  release_4-3 Revision
 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 
25  function __construct($a_id = "")
26  {
27  $this->id = $a_id;
28  $this->current_nr = self::$nr;
29  self::$nr++;
30  }
31 
37  function setFile($a_file)
38  {
39  $this->file = $a_file;
40  }
41 
47  function getFile()
48  {
49  return $this->file;
50  }
51 
57  function setAlternativeVideoFile($a_val)
58  {
59  $this->alt_video_file = $a_val;
60  }
61 
68  {
69  return $this->alt_video_file;
70  }
71 
77  function setAlternativeVideoMimeType($a_val)
78  {
79  $this->alt_video_mime = $a_val;
80  }
81 
88  {
89  return $this->alt_video_mime;
90  }
91 
97  function setDisplayHeight ($dHeight) {
98  $this->displayHeight = $dHeight;
99  }
100 
106  function getDisplayHeight () {
107  return $this->displayHeight;
108  }
109 
115  function setDisplayWidth($a_val)
116  {
117  $this->displayWidth = $a_val;
118  }
119 
125  function getDisplayWidth()
126  {
127  return $this->displayWidth;
128  }
129 
130  function setMimeType ($value) {
131  $this->mimeType = $value;
132  }
133 
139  function setVideoPreviewPic($a_val, $a_alt = "")
140  {
141  $this->video_preview_pic = $a_val;
142  $this->video_preview_pic_alt = $a_alt;
143  }
144 
151  {
152  return $this->video_preview_pic;
153  }
154 
160  function setTitle($a_val)
161  {
162  $this->title = $a_val;
163  }
164 
170  function getTitle()
171  {
172  return $this->title;
173  }
174 
180  function setDescription($a_val)
181  {
182  $this->description = $a_val;
183  }
184 
190  function getDescription()
191  {
192  return $this->description;
193  }
194 
200  function setForceAudioPreview($a_val)
201  {
202  $this->force_audio_preview = $a_val;
203  }
204 
211  {
212  return $this->force_audio_preview;
213  }
214 
218  function getMp3PlayerHtml($a_preview = false)
219  {
220  global $tpl;
221 
222  $tpl->addJavascript("./Services/MediaObjects/js/MediaObjects.js");
223 
224  if (!self::$lightbox_initialized)
225  {
226  include_once("./Services/UIComponent/Lightbox/classes/class.ilLightboxGUI.php");
227  $lb = new ilLightboxGUI("media_lightbox");
228  $lb->setWidth("660px");
229  $lb->addLightbox();
230  self::$lightbox_initialized = true;
231  }
232 
233  require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
234  include_once("./Services/MediaObjects/classes/class.ilExternalMediaAnalyzer.php");
235 
236  // youtube
237 /* if (ilExternalMediaAnalyzer::isYouTube($this->getFile()))
238  {
239  $p = ilExternalMediaAnalyzer::extractYouTubeParameters($this->getFile());
240  $html = '<object width="320" height="240">'.
241  '<param name="movie" value="http://www.youtube.com/v/'.$p["v"].'?fs=1">'.
242  '</param><param name="allowFullScreen" value="true"></param>'.
243  '<param name="allowscriptaccess" value="always">'.
244  '</param><embed src="http://www.youtube.com/v/'.$p["v"].'?fs=1" '.
245  'type="application/x-shockwave-flash" allowscriptaccess="always" '.
246  'allowfullscreen="true" width="320" height="240"></embed></object>';
247  return $html;
248  }
249 
250  // vimeo
251  if (ilExternalMediaAnalyzer::isVimeo($this->getFile()))
252  {
253  $p = ilExternalMediaAnalyzer::extractVimeoParameters($this->getFile());
254 
255  $html = '<iframe src="http://player.vimeo.com/video/'.$p["id"].'" width="320" height="240" '.
256  'frameborder="0"></iframe>';
257 
258  return $html;
259  }
260 */
261  $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
262  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
263 
264  // video tag
265  if (in_array($mimeType, array("video/mp4", "video/m4v", "video/rtmp",
266  "video/x-flv", "video/webm", "video/youtube", "video/vimeo", "video/ogg")))
267  {
269 
270  if ($mimeType == "video/quicktime")
271  {
272  $mimeType = "video/mov";
273  }
274 
275  $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
276 
277  // preview
278  if ($a_preview)
279  {
280  $mp_tpl->setCurrentBlock("preview");
281  if ($this->getVideoPreviewPic() != "")
282  {
283  $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
284  }
285  else
286  {
287  $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.png"));
288  }
289  $mp_tpl->setVariable("IMG_ALT", $this->video_preview_pic_alt);
290  $mp_tpl->setVariable("PTITLE", $this->getTitle());
291  $mp_tpl->parseCurrentBlock();
292  }
293 
294  // sources
295  $mp_tpl->setCurrentBlock("source");
296  $mp_tpl->setVariable("FILE", $this->getFile());
297  $mp_tpl->setVariable("MIME", $mimeType);
298  $mp_tpl->parseCurrentBlock();
299 
300  if (in_array($this->getAlternativeVideoMimeType(), array("video/mp4", "video/webm")))
301  {
302  $mp_tpl->setCurrentBlock("source");
303  $mp_tpl->setVariable("FILE", $this->getAlternativeVideoFile());
304  $mp_tpl->setVariable("MIME", $this->getAlternativeVideoMimeType());
305  $mp_tpl->parseCurrentBlock();
306  }
307 
308  $mp_tpl->setCurrentBlock("mejs_video");
309 
310  if ($a_preview)
311  {
312  $mp_tpl->setVariable("CLASS", "ilNoDisplay");
313  }
314 
315  $mp_tpl->setVariable("PLAYER_NR", $this->current_nr);
316  $height = $this->getDisplayHeight();
317  $width = $this->getDisplayWidth();
318  if (is_int(strpos($mimeType,"audio/mpeg")))
319  {
320  $height = "30";
321  }
322 
323  $mp_tpl->setVariable("DISPLAY_HEIGHT", $height);
324  $mp_tpl->setVariable("DISPLAY_WIDTH", $width);
325  $mp_tpl->setVariable("PREVIEW_PIC", $this->getVideoPreviewPic());
326  $mp_tpl->setVariable("SWF_FILE", ilPlayerUtil::getFlashVideoPlayerFilename(true));
327  $mp_tpl->setVariable("FFILE", $this->getFile());
328  $mp_tpl->setVariable("TITLE", $this->getTitle());
329  $mp_tpl->setVariable("DESCRIPTION", $this->getDescription());
330  $mp_tpl->parseCurrentBlock();
331  $r = $mp_tpl->get();
332 //echo htmlentities($r);
333  return $r;
334  }
335 
336  // audio/mpeg
337  if (is_int(strpos($mimeType,"audio/mpeg")) ||
338  in_array($mimeType, array("application/ogg", "audio/ogg")))
339  {
341  $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
342  $preview_output = false;
343  if ($this->getVideoPreviewPic() != "" || $this->getForceAudioPreview())
344  {
345  $mp_tpl->setCurrentBlock("apreview");
346  if ($this->getVideoPreviewPic() != "")
347  {
348  $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
349  }
350  else
351  {
352  $mp_tpl->setVariable("IMG_SRC", ilUtil::getImagePath("mcst_preview.png"));
353  }
354  $mp_tpl->setVariable("PTITLE", $this->getTitle());
355  $mp_tpl->parseCurrentBlock();
356  $preview_output = true;
357  }
358  $mp_tpl->setCurrentBlock("audio");
359  if ($preview_output)
360  {
361  $mp_tpl->setVariable("ASTYLE", "margin-top:-30px");
362  }
363  $mp_tpl->setVariable("AFILE", $this->getFile());
364  $mp_tpl->setVariable("APLAYER_NR", $this->current_nr);
365  $mp_tpl->setVariable("AHEIGHT", "30");
366  $mp_tpl->setVariable("AWIDTH", "320");
367  $mp_tpl->parseCurrentBlock();
368  return $mp_tpl->get();
369  }
370 
371  // images
372  if (is_int(strpos($mimeType,"image/")))
373  {
374  $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
375  $mp_tpl->setCurrentBlock("ipreview");
376  if ($this->getVideoPreviewPic() != "")
377  {
378  $mp_tpl->setVariable("IMG_SRC", $this->getVideoPreviewPic());
379  }
380  else
381  {
382  $mp_tpl->setVariable("IMG_SRC", $this->getFile());
383  }
384  $mp_tpl->setVariable("PTITLE", $this->getTitle());
385  $mp_tpl->parseCurrentBlock();
386 
387  $mp_tpl->setCurrentBlock("image");
388  $mp_tpl->setVariable("IFILE", $this->getFile());
389  $mp_tpl->setVariable("IPLAYER_NR", $this->current_nr);
390  $mp_tpl->setVariable("ITITLE", $this->getTitle());
391  $mp_tpl->setVariable("IDESCRIPTION", $this->getDescription());
392 
393  $height = $this->getDisplayHeight();
394  $width = $this->getDisplayWidth();
395 
396  $mp_tpl->setVariable("IHEIGHT", $height);
397  $mp_tpl->setVariable("IWIDTH", $width);
398  $mp_tpl->parseCurrentBlock();
399 
400  return $mp_tpl->get();
401  }
402 
403  // fallback, no preview mode
404  $mimeType = $this->mimeType == "" ? ilObjMediaObject::getMimeType(basename($this->getFile())) : $this->mimeType;
405  if (strpos($mimeType,"flv") === false
406  && strpos($mimeType,"audio/mpeg") === false
407  && strpos($mimeType,"image/png") === false
408  && strpos($mimeType,"image/gif") === false)
409  {
410 
411  $html = '<embed src="'.$this->getFile().'" '.
412  'type="'.$mimeType.'" '.
413  'ShowControls="1" '.
414  'autoplay="false" autostart="false" '.
415  'width="320" height="240" scale="aspect" ></embed>';
416  return $html;
417  }
418 
419 return;
420  $tpl->addJavaScript("./Services/MediaObjects/flash_flv_player/swfobject.js");
421  $mp_tpl = new ilTemplate("tpl.flv_player.html", true, true, "Services/MediaObjects");
422  $mp_tpl->setCurrentBlock("default");
423  $mp_tpl->setVariable("FILE", urlencode($this->getFile()));
424  $mp_tpl->setVariable("PLAYER_NR", $this->current_nr);
425  $mp_tpl->setVariable("DISPLAY_HEIGHT", strpos($mimeType,"audio/mpeg") === false ? "240" : "20");
426  $mp_tpl->setVariable("DISPLAY_WIDTH", "320");
427  $mp_tpl->parseCurrentBlock();
428  return $mp_tpl->get();
429  }
430 
437  function getPreviewHtml()
438  {
439  return $this->getMp3PlayerHtml(true);
440  }
441 
442 }
443 ?>