Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get Window tag? #4693

Closed
frakc opened this issue Aug 20, 2018 · 1 comment
Closed

How to get Window tag? #4693

frakc opened this issue Aug 20, 2018 · 1 comment
Assignees
Labels

Comments

@frakc
Copy link

frakc commented Aug 20, 2018

Issue description

When i try to get window tag, i always get null. Generally happens after i change media source

Reproduction steps

I feed concatenating mediaSource to player

private MediaSource createMediaSource(ExoVideo exoVideo) {
    Utils utils = new Utils();
    MediaSource[] playlist =
        utils.getPlaylist(context, mediaDataSourceFactory, manifestDataSourceFactory);
    Log.e("mcheck", "createMediaSource: size " + playlist.length);
    if (playlist.length == 1) return playlist[0];
    ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource(playlist);
    return concatenatingMediaSource;
  }

Concatenatingmediasource consists of several HLS MS where i put tags. Each of them checked to be non null.

 return new HlsMediaSource.Factory(mediaDataSourceFactory)
            .setAllowChunklessPreparation(true)
            .setTag(tag)
            .createMediaSource(uri);

I check for tag in onTracksChanged()

 @Override @SuppressWarnings("ReferenceEquality")
    public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
      Log.e("mcheck", "onTracksChanged: ");
      if (timeline != null) {
        Log.e("mcheck", "onTracksChanged: " + timeline.getWindowCount());
        if (timeline.getWindowCount() > 0) {
          Log.e("mcheck", "onTracksChanged: " + player.getCurrentTag());
          Log.e("mcheck", "onTracksChanged:||||||||||||||||||||||||||||||||||||||||||||||||||");
          for (int i = 0; i < timeline.getWindowCount(); i++) {
            Timeline.Window w = new Timeline.Window();
            timeline.getWindow(i, w,true);
            Log.e("mcheck", "onTracksAll: " + i + " " + w.tag);
          }
          Timeline.Window w = new Timeline.Window();
          timeline.getWindow(player.getCurrentWindowIndex(),w,true);
          EventBus.getDefault().post(new PlayingAdEvent(player.isPlayingAd()));
          playerCallback.onTrackEnded((String) w.tag,
              player.getCurrentWindowIndex());
        } else {

        }
      } else {
        Log.e("mcheck", "onTracksChanged: timeline null");
      }
    }
  }

when this method i called i getting following log, where all tags are null

    onTracksChanged: 
    onTracksChanged: 23
    onTracksChanged: null
    onTracksChanged:||||||||||||||||||||||||||||||||||||||||||||||||||
    onTracksAll: 0 null
    onTracksAll: 1 null
    onTracksAll: 2 null
    onTracksAll: 3 null
    onTracksAll: 4 null
    onTracksAll: 5 null
    onTracksAll: 6 null
    onTracksAll: 7 null
    onTracksAll: 8 null
    onTracksAll: 9 null
    onTracksAll: 10 null
    onTracksAll: 11 null
    onTracksAll: 12 null
    onTracksAll: 13 null
    onTracksAll: 14 null
    onTracksAll: 15 null
    onTracksAll: 16 null
    onTracksAll: 17 null
    onTracksAll: 18 null
    onTracksAll: 19 null
    onTracksAll: 20 null
    onTracksAll: 21 null
    onTracksAll: 22 null

Version of ExoPlayer being used

version 2.8.2

@tonihei tonihei self-assigned this Aug 20, 2018
@tonihei
Copy link
Collaborator

tonihei commented Aug 20, 2018

That's working as intended, but I agree it's not ideal.

When the playlist is prepared, it spawns off the preparation of all the playlist elements. Only after each child element is prepared, you'll see the tag when using window.tag or player.getCurrentTag(). Before the child element is prepared, the window is just an empty shell without any information and unfortunately also without tag. Please listen to onTimelineChanged to see the updates happen.

The reason behind this behaviour is that there is no 1:1 relation between media source and windows because each media source can have multiple windows. That's why we can't assign a tag as long as we don't know more about the media structure.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants