Orange-OpenSource / hasplayer.js

Http Adaptive Streaming javascript player based on HTML5 premium extensions (MSE/EME)
Other
197 stars 67 forks source link

hasplayer 1.14 not getting tracks (audio/text) #237

Closed pdoria closed 6 years ago

pdoria commented 6 years ago

Hi, calling getTracks() - for either type - always returns an empty array.

Stream sample: manifest.zip

Relevant code:

this.mediaPlayer.init(document.querySelector("#player"));
 this.mediaPlayer.addEventListener("loadeddata", this.onLoad(event));
 this.mediaPlayer.load(stream);

  onLoad(event: any) {
    console.log('loaded data: ', event);
    // Now is  the chance to get the audio and caption streams, if any.
    this.audioTracks = this.mediaPlayer.getTracks(MediaPlayer.TRACKS_TYPE.AUDIO);
    this.captions = this.mediaPlayer.getTracks(MediaPlayer.TRACKS_TYPE.TEXT);

    console.log("AUDIO TRACKS: ", this.audioTracks);
    console.log("CAPTIONS: ", this.captions);
  }

Any ideas would be greatly appreciated ;) TIA, Pedro

nicosang commented 6 years ago

Hi @pdoria ,

your stream has no text streamIndex, so captions array is logically empty. Could you, please, register the error event in order to know what happends (ex: mediaPlayer.addEventListener("error", onError);) ?

thanks, Nico

pdoria commented 6 years ago

Hi Nico,

Thanks for joining this thread :)

Yes I know that that particular stream as no captions. Was just testing for audio streams, although I'll offer a manifest sample later on with captions ;)

As for what you have suggested we are already doing that, even turned the debug level to 4...

  this.mediaPlayer.getDebug().setLevel(4);
  this.mediaPlayer.addEventListener("error", this.onError);

  onError(error:any) {
    console.error('Media player error: ', error);
  }

Unfortunately no error is thrown.

Achieving getting just the audio stream list would be victory now and I'm in a bit of loss as to what to do next.

TIA, Pedro

nicosang commented 6 years ago

could you, please, show us the logs of the hasplayer.js?

pdoria commented 6 years ago

Hi Nico,

Here it is hasplayer.zip

You'll notice that the completion of the MssParser occurs after getTracks completes ... so this might be the problem.

Thanks for your insights, Pedro

nicosang commented 6 years ago

Hi @pdoria ,

indeed the problem is the way you registered the callback : the onLoad function is called when you do the registration. I think you should register the loadeddata event like this :

this.mediaPlayer.addEventListener("loadeddata", this.onload);

it's the same way that you did for error event....

Nico

pdoria commented 6 years ago

Thank you Nico. Issue has been solved :)