问题
I actually cannot believe I couldn't find an answer to this as it appears to me as if it should be a common problem - am I using the wrong terminology?
However, I am looking for a way to switch the audiotrack of the video that is being sent to be played on chromecast. More precisely I'm talking about a multitrack video File embedding two audio lines (mkv-format).
I've not found any possibility to do this using the (Android) SDK, nor could I change it using JavaScript on the Receiver App itself. (This would at least enable me to implement the ability using a custom receiver).
From my research I found, that the video element is supposed to get a audioTracks and videoTracks attribute but accordingly it is not yet implemented by any browser and thus obviously not available on chromecast. (http://www.w3schools.com/tags/av_prop_audiotracks.asp)
Any suggestions?
回答1:
Look at the media player library documentation for cycling through audio streams: https://developers.google.com/cast/docs/player
window.changeLanguage = function() {
var currentLanguage = null;
var streamCount = this.protocol_.getStreamCount();
var streamInfo;
for (var i = 0; i < streamCount; i++) {
if (protocol.isStreamEnabled(i)) {
streamInfo = protocol.getStreamInfo(i);
if (streamInfo.mimeType.indexOf('audio') === 0) {
if (streamInfo.language) {
currentLanguage = i;
break;
}
}
}
}
if (currentLanguage === null) {
currentLanguage = 0;
}
i = currentLanguage + 1;
while (i !== currentLanguage) {
if (i === streamCount) {
i = 0;
}
streamInfo = protocol.getStreamInfo(i);
if (streamInfo.mimeType.indexOf('audio') === 0) {
protocol.enableStream(i, true);
protocol.enableStream(currentLanguage, false);
break;
}
i++;
}
if (i !== currentLanguage) {
this.player_.reload();
}
};
来源:https://stackoverflow.com/questions/23174160/switching-audiotrack-on-chromecast