我在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>
我变得疯狂,因为我找不到问题,我的控制台上没有错误。
我该如何解决?
答案 0 :(得分:0)
感谢用户Alvaro Montoro,我找到了here解决方案。
我将此功能添加到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
}
});
仅当玩家身高至少为720px时才会起作用。
感谢你的全部