gpt4 book ai didi

android - Chromecast 多语言播放就绪未检测到语言

转载 作者:行者123 更新时间:2023-11-30 02:28:57 26 4
gpt4 key购买 nike

我正在尝试在 Chromecast 上播放多语言音轨。它播放视频/音频文件,但不会从英语切换到西类牙语。我可以在 silverlight 播放器中使用相同的文件进行切换。我已将我的 chromecast 播放器语言和我的 android 手机语言设置为西类牙语。在 Google Cast SDK 开发者控制台中,我添加了西类牙语作为备用轨道。

我已经使用 google 指南中指定的代码添加了我的自定义播放器,但是指南中的代码似乎无法直接复制和粘贴。有人能告诉我为什么 protocol.getStreamCount() 是 0 吗?通话时间是否正确?这是我正在使用的整个播放器,请特别注意 window.changeLanguage = function()... 和 changeLanguage 调用。非常感谢任何帮助!

<html>
<head>
<title>Test Player</title>
<script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
<script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/mediaplayer/1.0.0/media_player.js"></script>
<link rel="stylesheet" type="text/css" href="chromecast.css" />
</head>
<body>
<video id='vid' />


<script type="text/javascript">
if (window.location.href.indexOf('Debug=true') != -1) {
cast.receiver.logger.setLevelValue(cast.receiver.LoggerLevel.DEBUG);
cast.player.api.setLoggerLevel(cast.player.api.LoggerLevel.DEBUG);
}

var mediaElement = document.getElementById('vid');
var protocol = null;
// Create the media manager. This will handle all media messages by default.
window.mediaManager = new cast.receiver.MediaManager(mediaElement);
window.defaultOnLoad = mediaManager.onLoad;
mediaManager.onLoad = function (event) {
if (window.player !== null) {
player.unload(); // Must unload before starting again.
window.player = null;
}
if (event.data['media'] && event.data['media']['contentId']) {
console.log('Starting media application');
var url = event.data['media']['contentId'];
window.host = new cast.player.api.Host({'mediaElement':mediaElement, 'url':url});
var ext = url.substring(url.lastIndexOf('.'), url.length);
var initStart = event.data['media']['currentTime'] || 0;
var autoplay = event.data['autoplay'] || true;
mediaElement.autoplay = autoplay; // Make sure autoplay get's set

if (url.lastIndexOf('.m3u8') >= 0)
{
// HTTP Live Streaming
protocol = cast.player.api.CreateHlsStreamingProtocol(host);
}
else if (url.lastIndexOf('.mpd') >= 0)
{
// MPEG-DASH
protocol = cast.player.api.CreateDashStreamingProtocol(host);
}
else if (url.indexOf('.ism/') >= 0)
{
// Smooth Streaming
protocol = cast.player.api.CreateSmoothStreamingProtocol(host);
}
// How to override a method in Host. I know that it's safe to just provide this
// method.
host.onError = function(errorCode) {
console.log("Fatal Error - " + errorCode);
if (window.player) {
window.player.unload();
window.player = null;
}
};
console.log("we have protocol " + ext);
if (protocol !== null) {
console.log("Starting Media Player Library");
window.player = new cast.player.api.Player(host);
window.player.load(protocol, initStart);
changeLanguage();
}
else {
window.defaultOnLoad(event); // do the default process
}
}
}

window.changeLanguage = function() {
var currentLanguage = null;
var streamCount = protocol.getStreamCount();
console.log("streamCount: " + streamCount);
var streamInfo;
for (var i = 0; i < streamCount; i++) {
console.log("isStreamEnabled " + i + "? " + protocol.isStreamEnabled(i));
if (protocol.isStreamEnabled(i)) {
streamInfo = protocol.getStreamInfo(i);
console.log("streamInfo isAudio? " + streamInfo.mimeType.indexOf('audio'));
if (streamInfo.mimeType.indexOf('audio') === 0) {
if (streamInfo.language) {
console.log("streamInfo.language: " + streamInfo.language);
currentLanguage = i;
break;
}
}
}
}

if (currentLanguage === null) {
currentLanguage = 0;
}

i = currentLanguage + 1;
console.log("i: " + i);
console.log("currentLanguage: " + currentLanguage);
while (i !== currentLanguage) {
if (i === streamCount) {
console.log("resetting i to 0");
i = 0;
}

streamInfo = protocol.getStreamInfo(i);
if (streamInfo.mimeType.indexOf('audio') === 0) {
protocol.enableStream(i, true);
protocol.enableStream(currentLanguage, false);

console.log("Enabling: " + i);
console.log("Disabling: " + currentLanguage);
break;
}

i++;
}

if (i !== currentLanguage) {
console.log("reloading window player" + window.player);
window.player.reload();
}
};

window.player = null;
console.log('Application is ready, starting system');
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
castReceiverManager.start();
</script>
</body>
</html>

Chromecast 控制台:

Application is ready, starting system

Starting media application

we have protocol .ism/manifest

Starting Media Player Library

streamCount: 0

i: 1

currentLanguage: 0

编辑

我进入控制台并调用以下命令加载后:

this.protocol.getStreamCount()

2

所以这显然是一个时间问题。流完全加载后,我需要调用 changeLanguage。我正在调查什么时候调用它是合适的。如果有任何帮助,我将不胜感激,但我会尝试用谷歌搜索这个答案,因为我确信这是一个时间问题。

最佳答案

答案是:

host.onManifestReady = function() {
changeLanguage();
};

这将为何时拉出备用音轨提供正确的时间。

关于android - Chromecast 多语言播放就绪未检测到语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27536849/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com