shaka-project / shaka-player

JavaScript player library / DASH & HLS client / MSE-EME player
Apache License 2.0
7.11k stars 1.33k forks source link

How to get the AudioTracks in Shaka Player for Dynamic videos (uploaded videos at azure portal) - using React js #4562

Closed sadhashivamp closed 1 year ago

sadhashivamp commented 1 year ago

Have you read the Tutorials?

Have you read the FAQ and checked for duplicate open issues?

What version of Shaka Player are you using?

4.2.2 Please ask your question

Actually exact issue is for static videos I got all data like resolutions, playback speed, Audio tracks and captions, but when am trying dynamic video like where I can uploaded videos in azure portals. so that azure videos not getting audio tracks. It showing languages "undetermined

this is my code

class Shaka2 extends React.PureComponent { constructor(props) { super(props); this.state = {};

this.video = React.createRef();
this.container = React.createRef();
this.onErrorEvent = this.onErrorEvent.bind(this);
this.onError = this.onError.bind(this);

}

onErrorEvent(event) { this.onError(event.detail); }

onError(error) { console.error("Error code", error.code, "object", error); }

componentDidMount() { const manifestUri = "https://vodemedia-usea.streaming.media.azure.net/e8490ffc-69c9-4d4a-b1d6-30c09da017e6/The Bad Guys_2022.ism/manifest(format=mpd-time-cmaf,encryption=cenc)";

const videoElement = this.video.current;
const containerElement = this.container.current;

console.log("videoElement", videoElement)
const player = new shaka.Player(videoElement);
console.log("player", player)
const ui = new shaka.ui.Overlay(player, containerElement, videoElement);
ui.getControls();

// var data = player.S.c
// console.log(data)

ShakaUI.Controls.registerElement("forward_10", new ForwardTenButton.Factory());
ShakaUI.Controls.registerElement("rewind_10", new RewindTenButton.Factory());

const config = {
  controlPanelElements: [
    'skip',
    'forward_10',
    'play_pause',
    'rewind_10',
    'time_and_duration',
    'spacer',
    'mute',
    'volume',
    'fullscreen',
    'overflow_menu',
  ],
  overflowMenuButtons: [
    'captions',
    'quality',
    'language',
    'picture_in_picture',
    'cast',
    'playback_rate',
  ],
};

ui.configure(config);
ui.getControls().getLocalization().changeLocale(["el"]); // try to change menu language
const controls = ui.getControls();

const localization = controls.getLocalization();
console.log("controls.getLocalization();", controls.getLocalization())

player.configure({
  drm: {
    servers: {
      'com.widevine.alpha': licenseServer,
    },
    advanced: {
      'com.widevine.alpha': {
        'videoRobustness': 'SW_SECURE_CRYPTO',
        'audioRobustness': 'SW_SECURE_CRYPTO'
      }
    }
  },
  preferredTextLanguage: 'en'
});

Actually i tried like this for getting audio tracks, but not got any data

// let tracks = player.audioTracks();
// tracks.addEventListener('change', function () {
//   for (let i = 0; i < tracks.length; i++) {
//     let track = tracks[i];
//     if (track.enabled) {
//       console.log(track.label);
//       return;
//     }
//   }
// });

var url = player.load(manifestUri)
console.log("manifests", url)

player.configure('streaming.alwaysStreamText', true)
player.load(manifestUri).then(function () {
  player.addTextTrack(captionUrl);
  var tracks = player.getTextTracks();
  console.log('tracks_text', tracks)
  if (tracks) {
    for (let i = 0; i < tracks?.length; i++) {
      player.selectTextTrack(tracks[i]);
    }
  }
});

const tracks = videoElement.audioTracks;
// var new1 = player.selectVariantTrack();
console.log("data1", tracks)

player.addEventListener("error", this.onErrorEvent);

player.load(manifestUri).then(() => {
  console.log("The video has now been loaded!");
}).catch(this.onError);

}

render() { return ( <div style={{ width: '1040px', height: '600px', margin: 'auto' }} ref={this.container}> <video data-shaka-player width="100%" height="100%" ref={this.video} autoPlay />

);

} }

export default Shaka2;

sadhashivamp commented 1 year ago

Can any one please help me , how to get audio tracks for me getting languages are undetermined

multiplexer2 commented 1 year ago

When uploading to AMS you should assign proper 3 letter ISO 639 language codes to the audio tracks. Your audio tracks currently have the language code 'und' (undetermined).

sadhashivamp commented 1 year ago

When uploading to AMS you should assign proper 3 letter ISO 639 language codes to the audio tracks. Your audio tracks currently have the language code 'und' (undetermined).

Hello @multiplexer2 thanks for replied on my issue actually here we uploading only video files with subtitle vtt file. So here we didn't uploading any audio files. so we thought audio tracks will automatically coming....like when we used static video files its getting all data. so now i didnt got audio data for azure uploaded files.

github-actions[bot] commented 1 year ago

Closing due to inactivity. If this is still an issue for you or if you have further questions, the OP can ask shaka-bot to reopen it by including @shaka-bot reopen in a comment.