YouTube Player API
class player{
public function player(){
if(array_key_exists('t',$_REQUEST)
and array_key_exists('l',$_REQUEST)
and array_key_exists('url',$_REQUEST)){
$this->urltime = $_GET['t'];
$this->playlist = $_GET['l'];
$this->yturl = $_GET['url'];
$this->yturl_3item = $this->para($_GET['url']);
$temp = array();
foreach ($this->yturl_3item as $val){
$temp[count($temp)] = sprintf("'%s'",$val);
}
$this->list_item = '['.implode(",",$temp ).']';
$this->you_player_api($this->playlist,$this->yturl_3item[0],$this->list_item);
}else{
$this->you_player_api('PLvswSo32Xlu_tBfEDzpuFQ-lUFP1_Aq5I','_sQSXwdtxlY','["GLyYUyVH2PI","RgKAFK5djSk"]');
}
}
public function player_area(){
$div_area = sprintf('<div id = "player_area" >
<div id = "player"></div>
</div>
');
echo $div_area;
}
public function debug_show(){
echo '<pre>';
echo $this->urltime;
echo '<br>';
echo $this->playlist;
echo '<br>';
echo $this->yturl;
echo '<br>';
print_r( $this->yturl_3item);
echo $this->yturl_3item[0];
}
public function para($url){
$temp=array();
$temp2=array();
$temp=explode('=',$url);
$temp2=explode('|',$temp['1']);
return $temp2;
}
public function you_player_api($playlist,$videoid,$array_list){
$player = sprintf("
<script>
var tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
var playlist = '%s';
var videoid
= '%s';
var array_list = %s;
var h = '240';
var w = '320'
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: h,
width: w,
videoId: 'CNNDRO3imrs',
playerVars:{
'controls':'1',
'disablekb':'0',
'playsinline':'0'
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange,
'onError':onPlayerError
}
});
}
function onPlayerReady(event) {
//event.target.cuePlaylist({list:'PLvswSo32Xlu9BOn94xy-Xd_mTsMIny639'});
var j = event.target.cuePlaylist({list:playlist});
console.log (j.length);
if(j.length == 0){
one_list_play(event.target);
}
}
function onPlayerStateChange(event) {
console.log('onPlayerStateChange');
console.log(player.getAvailableQualityLevels());
console.log(player.getPlaybackQuality());
event.target.setPlaybackQuality('tiny');
if(event.target.getPlayerState() === 5 ){
event.target.setSize(w,h);
var list_items = event.target.getPlaylist();
var list_index = list_items.indexOf(videoid);
if(list_index >-1 ){
//event.target.loadPlaylist({list:playlist,index:list_index,startSeconds:3});
event.target.playVideoAt(list_index);
}
if(list_index == -1 ){
//event.target.loadPlaylist({playlist:array_list});
one_list_play(event.target);
}
}
}
function one_list_play(event){
console.log('000111');
event.loadPlaylist({playlist:array_list});
}
function onPlayerError(event){
event.target.nextVideo();
console.log('onPlayerError');
}
</script>"
,$playlist,$videoid,$array_list);
echo $player;
}
}