<?php
include_once "tadtools_header.php";
include_once "jquery.php";

class projekktor{
	var $image;
	var $file;
	var $width;
	var $height;
	var $mode;
  var $display;
  var $id;
  var $title;

	//建構函數
	function projekktor($id="",$file="",$image="",$width="",$height="",$mode="",$display="",$other_code="",$title=""){
		$this->width=(empty($width))?480:$width;
		$this->height=(empty($height))?360:$height;
		$this->file=$file;
		$this->image=$image;
		$this->mode=$mode;
		$this->display=$display;
		$this->id=$id;
		$this->other_code=$other_code;
		$this->title=$title;
	}

	//設定自定義設寬度
	function setWidth($width=""){
		$this->width=$width;
	}

	//設定自定義設高度
	function setHeight($height=""){
		$this->height=$height;
	}
	
	//設定自定義影片檔
	function setFile($file=""){
		$this->file=$file;
	}
	
	//設定自定義縮圖
	function setImage($image=""){
		$this->image=$image;
	}

  function mime_type($filename) {

      $mime_types = array(
          // audio/video
          'mp3' => 'audio/mpeg',
          'mp4' => 'video/mp4',
          'flv' => 'video/flv',
          'ogg' => 'video/ogg',
          'ogv' => 'video/ogv',
          'webm' => 'video/webm'
      );

      //if(substr($filename,0,4)=="http")return 'video/youtube';

      $ext = strtolower(array_pop(explode('.',$filename)));
      
      if (array_key_exists($ext, $mime_types)) {
          return $mime_types[$ext];
      //}elseif(function_exists('finfo_open')) {
      //    $finfo = finfo_open(FILEINFO_MIME);
      //    $mimetype = finfo_file($finfo, $filename);
      //    finfo_close($finfo);
      //    return $mimetype;
      }else {
          return 'video/youtube';
      }
  }



	//產生播放器
	function render(){
    $playlistfile="";
    if($this->mode=="playlist"){
      $mime="text/xml";
      $file="";
      $play_place="<div id='mediaspace{$this->id}'></div>";
      $poster="";
      $title="";
    }else{
      $file="file:'{$this->file}',";
      $mime=$this->mime_type($this->file);
      $play_place="<video id='mediaspace{$this->id}' class='projekktor' poster='{$this->image}' title='{$this->title}' controls>
        <source src='{$this->file}' type='$mime' />
    </video>";
      $poster="poster: '{$this->image}',";
      $title="title: '{$this->title}',";
    }

    
    $wh=($this->mode=='pda')?"width:screen.width,\nheight: pda_height, ":"width: {$this->width},\nheight: {$this->height},";
        
    
    $jquery=get_jquery();

    $player="
    <link rel='stylesheet' href='".TADTOOLS_URL."/projekktor/theme/style.css' type='text/css' media='screen' />
    <link rel='stylesheet' href='".TADTOOLS_URL."/projekktor/projekktor.logo.css' type='text/css' media='screen' />
    <link rel='stylesheet' href='".TADTOOLS_URL."/projekktor/projekktor.share.css' type='text/css' media='screen' />
    <link rel='stylesheet' href='".TADTOOLS_URL."/projekktor/projekktor.postertitle.css' type='text/css' media='screen' />
    $jquery
    <script type='text/javascript' src='".TADTOOLS_URL."/projekktor/projekktor.min.js'></script>
    <script type='text/javascript' src='".TADTOOLS_URL."/projekktor/projekktor.logo.js'></script>
    <script type='text/javascript' src='".TADTOOLS_URL."/projekktor/projekktor.share.js'></script>
    <script type='text/javascript' src='".TADTOOLS_URL."/projekktor/projekktor.postertitle.js'></script>
    $play_place


    <script type='text/javascript'>
  	$(document).ready(function() {
  	    projekktor('#mediaspace{$this->id}', {
          $file
          $title
          controls: true,
          autoplay: false,
          continuous:true,
          $wh
          $poster
          addplugins: ['logo','share'],
          {$this->other_code}
          playerFlashMP4:'".TADTOOLS_URL."/projekktor/jarisplayer.swf',
          playerFlashMP3:'".TADTOOLS_URL."/projekktor/jarisplayer.swf'
          
        });
  	});
    </script>
";
    return $player;
  }

}
?>
