google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.7k stars 6.02k forks source link

ConcatenatingMediaSource #4466

Closed taimoorMalik closed 6 years ago

taimoorMalik commented 6 years ago

Hello, how can i set title of the dynamic ConcatenatingMediaSource ? i can't fine setDisplayName with MediaSource its only available with SimpleMediaSource. Regards

tonihei commented 6 years ago

We do not support setting a title to a media source directly. But each MediaSource has a tag you can use to store additional information. For example new ExtractorMediaSource.Builder(...).setTag(title).build(). And then you can use player.getCurrentTag() to retrieve the title of the currently playing media source.

Aside: There is no such thing as a SimpleMediaSource. Not sure where you got this from?

taimoorMalik commented 6 years ago

Hello thanks for reply i'm using exoplayer api 2.8.1 and it has SimpleMediaSource and its working fine if i play single video i can set title as well but i need to implement next and previous video functionality so trying to implement ConcatenatingMediaSource its working fine but i can't find a way to display title for each video on toolbar and if get the current tag how will i display it as Video title?

taimoorMalik commented 6 years ago

Following is my method which recieves urls and make ConcatenatingMediaSource

` public void addMedia(String[] url)

{
    MediaSource mediaSourcee;

    DefaultBandwidthMeter bandwidthMeterA      = new DefaultBandwidthMeter();
    DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(VideoViewActivity.this, Util.getUserAgent(VideoViewActivity.this, "demo"), bandwidthMeterA);

    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();

    for(int i = 0; i < url.length; i++)

    {
        mediaSourcee = new ExtractorMediaSource(Uri.parse(url[i]), dataSourceFactory, extractorsFactory, null, null);
        ConcatenatingMediaSource.addMediaSource(mediaSourcee);

    }

    PlayVideo(ConcatenatingMediaSource);

}

void PlayVideo(ConcatenatingMediaSource path)

{
        player.prepare(path);
        player.setPlayWhenReady(true);
}

`

tonihei commented 6 years ago

There is no build-in way to display the title with our UI. I'd suggest asking this question on StackOverflow or similar sites as displaying text is a generic Android question.

taimoorMalik commented 6 years ago

Well my question wasn't about how to display a text my question was how can i pass addition video info such as video name to mediaSource rather than only String array of urls.

tonihei commented 6 years ago

As I explained above, please you setTag and getCurrentTag for that.

taimoorMalik commented 6 years ago

Ok i will try, thanks for your time :)

On Wed, Jul 4, 2018, 9:14 PM tonihei notifications@github.com wrote:

As I explained above, please you setTag and getCurrentTag for that.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/ExoPlayer/issues/4466#issuecomment-402519486, or mute the thread https://github.com/notifications/unsubscribe-auth/AXqNOHAK3B--6CS5U56Jt3J-9UcdVIo9ks5uDOnygaJpZM4VCUvc .

tim4dev commented 6 years ago

Cannot resolve symbol 'Builder' :

new ExtractorMediaSource.Builder

@taimoorMalik if you find the answer first, please share it here;)

tonihei commented 6 years ago

@tim4dev It's actually Factory not Builder. My bad :(

tim4dev commented 6 years ago

I'm new to using ExoPlayer. I use the example code for help.

I want to make a playlist of local files (and at the same time show what file name is currently playing). Here's how I do it:

dataSourceFactory = new DefaultDataSourceFactory(...);
mediaSourceFactory = new ExtractorMediaSource.Factory(dataSourceFactory);

mediaSourceList = new ArrayList<>();

for (<each local File>) {
    MediaSource source = mediaSourceFactory.createMediaSource(
                        Uri.fromFile(<local File>));
    // I need here something like this:
    // source.setTag(file.getName());

    mediaSourceList.add(source);
}

concatMediaSource.addMediaSources(mediaSourceList);

However, there is no such method MediaSource.setTag

taimoorMalik commented 6 years ago

Hello i were playing and displaying Video text with this code for single video private ExoVideoView videoView; SimpleMediaSource mediaSource; String path = "file:///storage/emulated/0/Download/Sample.mkv"; void PlayVideo(String path) { File file = new File(path); String strFileName = file.getName(); mediaSource = new SimpleMediaSource(path); mediaSource.setDisplayName(strFileName); videoView.play(mediaSource, false); }

But my requirement is to play all videos in the directory so need concatenation media source but the problem is ConcatenatingMediaSource.addMediaSource() takes MediaSource as parameter not SimpleMediaSource and MediaSource doesn't have mediaSource.setDisplayName(") method for setting name of video.

tonihei commented 6 years ago

That looks like custom code around ExoPlayer (and we can't help you debug that). Please look for the place where ExtractorMediaSource.Factory is used and set the tag there.

tonihei commented 6 years ago

Closing because I think the question is answered.