Switching Audiotrack on Chromecast

空扰寡人 提交于 2020-01-05 05:30:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!