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

MediaItem.Builder() doesn't contain StreamType in ExoPlayer 2.12.0 #7915

Closed
menscikov opened this issue Sep 15, 2020 · 7 comments
Closed

MediaItem.Builder() doesn't contain StreamType in ExoPlayer 2.12.0 #7915

menscikov opened this issue Sep 15, 2020 · 7 comments
Assignees
Labels

Comments

@menscikov
Copy link

menscikov commented Sep 15, 2020

Hello,

Until ExoPlayer 2.12.0 i used MediaInfo.Builder() where i could set media stream type, for example: .setStreamType(MediaInfo.STREAM_TYPE_LIVE) and then i passed all information to the MediaQueueItem.Builder() to cast video to Google Chromecast.

In the new ExoPlayer 2.12.0 version i have to use MediaItem.Builder() now. And it is impossible to set media stream type now.
Or maybe i'm missing something?

Thank you.

@menscikov menscikov changed the title MediaItem.Builder() doesn't contain StreamType MediaItem.Builder() doesn't contain StreamType in ExoPlayer 2.12.0 Sep 15, 2020
@icbaker icbaker assigned icbaker and marcbaechinger and unassigned icbaker Sep 15, 2020
@menscikov
Copy link
Author

There is also a problem with com.google.android.exoplayer2.MediaMetadata class.
It's only accepting "title" now.

Earlier i used com.google.android.gms.cast.MediaMetadata class, and i could set "title", "subtitle", "image" and other options to metadata with MediaInfo.Builder().

But now MediaItem.Builder() is only accepting MediaMetadata class from com.google.android.exoplayer2.

@menscikov
Copy link
Author

Maybe it's better to leave MediaQueueItem.Builder() and make CastPlayer.loadItem() method not deprecated for Google Chromecast?

@marcbaechinger
Copy link
Contributor

You can pass a MediaItemConverter to the constructor of the CastPlayer. This lets you convert the MediaItem to a MediaQueueItem which is then sent to RemoteMediaClient.

If you want to transport custom data with the MediaItem you can do so by using new MediaItem.Builder().setTag(object). This can be retrieved in the converter by using mediaItem.playbackProperties.tag and then converted to the MediaQueueItem .

@menscikov
Copy link
Author

menscikov commented Sep 15, 2020

You can pass a MediaItemConverter to the constructor of the CastPlayer. This lets you convert the MediaItem to a MediaQueueItem which is then sent to RemoteMediaClient.

If you want to transport custom data with the MediaItem you can do so by using new MediaItem.Builder().setTag(object). This can be retrieved in the converter by using mediaItem.playbackProperties.tag and then converted to the MediaQueueItem .

Could you please give an example how to do that?
I can't understand how can i convert MediaQueueItem to MediaItem with all options, like "streamType" and MediaMetadata "title", "subtitle", "image"?
CastPlayer is accepting only MediaItem now in ExoPlayer 2.12.0 version.

DefaultMediaItemConverter().toMediaItem class doesn't allow to do this.

@marcbaechinger
Copy link
Contributor

marcbaechinger commented Sep 15, 2020

Sorry to not give you enough details. You are right it's confusing. Specifically because the conversion back which confused you is currently unused. Please accept my apologies of not being clear here.

On the bright side, this should make things easier for you. You said above that your app is building a MediaQueueItem with MediaQueueItem.Builder(). If you aim for doing this with the least possible changes in you code it would probably be something like the following:

Implement your custom MediaItemConverter:

public class CustomConverter implements MediaItemConverter {
  public MediaQueueItem toMediaQueueItem(MediaItem mediaItem) {
       // The MediaQueueItem you build is expected to be in the tag.
       return (MediaQueueItem)mediaItem.playbackProperties.getTag();
  }
  public MediaItem toMediaItem(MediaQueueItem Item) {
      // This should give the same as when you build your media item to be passed to ExoPlayer.
      return new MediaItem.Builder()
          .setUri(item.getMedia().getContentUrl())
          .setTag(item)
          .build();
  }
}

// The custom converter is used to create the cast player.
CastPlayer castPlayer = CastPlayer(castContext, new CustomConverter());

// You code builds a MediaQueueItem
MediaQueueItem queueItem = MediaQueueItem.Builder().setXyz().build();
// and ads it as the tag of the media item
MediaItem mediaItem = new MediaItem.Build().setUri(uri).setTag(queueItem).build();

// Add the item to the cast player which uses the converter internally.
castPlayer.addMediaItem(mediaItem);
simpleExoPlayer.addMediaItem(mediaItem);

You could use any object as the tag. But given your code builds the media queue item already it's probably easiest to just use this.

Your app can now use the same API like addMediaItem on both, the CastPlayer and SimpleExoPlayer because both implement the Player interface. ExoPlayer will just ignore the tag which you only need to create the queue item.

@menscikov
Copy link
Author

Thank you very much for the explanation. It's working now!

@marcbaechinger
Copy link
Contributor

Cool. I'm glad it works :)

I close this issue for now. Please re-open if you have further questions. Happy to help!

@google google locked and limited conversation to collaborators Nov 15, 2020
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

3 participants