我在CodeIgniter上,我遇到了这个问题,使用next_video API功能,单击按钮时,新视频的质量比以前的视频低,所以基本上第一个视频总是按照我的建议质量,下一个总是默认质量。
在我的template
上,我有这个div
:
<div id="ytapiplayer">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>
这是我custom.js
:
function loadNewVideo(id, startSeconds,quality,ads) {
console.log(ytplayer);
if (ytplayer) {
$("#current progress-bar").width("0%");
if(ads != '')
{
tempVideo = id;
id = ads;
console.log(ads);
}
ytplayer.loadVideoById(id, parseInt(startSeconds),'hd720');
if(is_mobile)
{
$("#videoPlayer").removeClass('active');
$("#thumbnail").addClass('hidePlayer');
}
}
else
{
ytplayer = new YT.Player('ytapiplayer', {
height: '425',
width: '356',
videoId: id,
suggestedQuality: 'hd720',
playerVars: {'controls': youtube_control,'autoplay':1 },
events: {
'onReady': onYouTubePlayerReady
}
});
if(start_youtube =="1")
{
$("#videoPlayer").addClass('active');
$("#thumbnail").removeClass('hidePlayer');
$("#amazon").hide();
}
if(is_mobile)
{
$("#videoPlayer").addClass('active');
$("#thumbnail").removeClass('hidePlayer');
$('#thumbnailx ,.info-thumb').popover('show');
setTimeout(function() {$('#thumbnailx ,.info-thumb').popover('hide');}, 5000);
}
}
}
这是我的header
:
<script src="//www.youtube.com/iframe_api"></script>
<script type="text/javascript">
var base_url = '<?php echo base_url(); ?>';
var popup = '<?php echo $this->config->item("popup"); ?>';
var is_mobile = '<?php echo $this->agent->is_mobile(); ?>';
var title = "<?php echo $this->config->item("title"); ?>";
var label_loading = "<?php echo ___('label_loading'); ?>";
var extend = "<?php echo $this->config->item('use_database'); ?>";
var start_youtube = "0";
var label_loading_playlist= "<?php echo ___('label_loading_playlist'); ?>";
var error_max = "<?php echo ___('error_playlist_max'); ?>";
var hide_ads_registered = "<?php echo $this->config->item('hide_ads_registered'); ?>";
var is_logged = "<?php echo is_logged(); ?>";
var youtube_control = "<?php echo $this->config->item('youtube_controls'); ?>";
var youtube_quality = "<?php echo $this->config->item('youtube_quality'); ?>";
</script>
我变得疯狂,因为我找不到问题,我的控制台上没有错误。
我该如何解决它?
感谢用户阿尔瓦罗·蒙托罗,我在这里找到了解决方案。
我将这个函数添加到custom.js
:
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING) {
event.target.setPlaybackQuality('hd720'); // <-- WORKS!
}
}
在同一个JavaScript中,我编辑了ytplayer
:
ytplayer = new YT.Player('ytapiplayer', {
height: '100%',
width: '100%',
videoId: id,
suggestedQuality: 'hd720',
playerVars: {'controls': youtube_control,'autoplay':1 },
events: {
'onReady': onYouTubePlayerReady,
'onStateChange': onPlayerStateChange
}
});
仅当播放器大小高度至少为 720 像素时,这才有效。
感谢你们所有人