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.71k stars 6.02k forks source link

Some Audios are not sync with the time #7355

Closed zjamshidi closed 4 years ago

zjamshidi commented 4 years ago

[REQUIRED] Issue description

I want to play part of the audio, e.g. start from a specific point. I listen to the audio on my laptop record the start point and then use seekTo method to initialize the audio. But the audio play a bit earlier.

[REQUIRED] Reproduction steps

In the demo app, change PlayerActivity.initializePlayer method as follow

...
    player.seekTo(890000);
    player.prepare(mediaSource, false, false);

Run the demo app with the following command adb.exe shell am start -a com.google.android.exoplayer.demo.action.VIEW -d "http://traffic.libsyn.com/booksaregreat/Emotional_Intelligence_2.0_by_Travis_Bradberry.mp3?dest-id=632295"

Also download and play the audio and listen to time 14:50 they are not the same.

[REQUIRED] Link to test content

here is the command to start demo app, you just need to change the initializePlayer method adb.exe shell am start -a com.google.android.exoplayer.demo.action.VIEW -d "http://traffic.libsyn.com/booksaregreat/Emotional_Intelligence_2.0_by_Travis_Bradberry.mp3?dest-id=632295"

[REQUIRED] A full bug report captured from the device

[REQUIRED] Version of ExoPlayer being used

I have checked out release-v2 branch

[REQUIRED] Device(s) and version(s) of Android being used

I have tried on several devices, Xiaomi Note 5 specifically

krocard commented 4 years ago

@kim-vde, does ExoPlayer supports exact seeking for mp3 in ?

krocard commented 4 years ago

I found the relevant feature request: https://github.com/google/ExoPlayer/issues/6787#issuecomment-585904489

@zjamshidi You need to set the flag Mp3Extractor.FLAG_ENABLE_INDEX_SEEKING to seek to an arbitrary timestamp in mp3 (this is due to the lack of 0(1) way of finding to which offset to seek, making such seek potentially slow).

More info on the feature request comment I linked.

zjamshidi commented 4 years ago

Thanks for your reply. I'm checking it.

zjamshidi commented 4 years ago

It seems it's not released yet. It would be nice to provide a sample for it. I'm following main-demo coding and I don't know how to get the extractor.

zjamshidi commented 4 years ago

Do you have any ETA for the next release?

kim-vde commented 4 years ago

It is indeed not released yet. We plan to update the documentation when it is released. @ojw28, do you have any idea of when this is going to be?

krocard commented 4 years ago

I'm following main-demo coding and I don't know how to get the extractor.

Set the flag when creating the ProgressiveMediaSource:

var extractorsFactory = new DefaultExtractorsFactory()
            . setMp3ExtractorFlags(Mp3Extractor. FLAG_ENABLE_INDEX_SEEKING);
var mediaSourceFactory =
            new ProgressiveMediaSource.Factory(dataSourceFactory, extractorsFactory);

The demo code uses the DefaultMediaSourceFactory that does not allow to inject it's ProgressiveMediaSource.

In your app, if you are not going to play chunked HTTP streams (DASH, HLS or SS) and thus do not need DefaultMediaSourceFactory, use the ProgressiveMediaSource directly:

var player = new SimpleExoPlayer.Builder(/* context= */ this, renderersFactory)
              .setMediaSourceFactory(mediaSourceFactory)
              // ...
              .build();

For context the player is created here in the demo app. This is what needs to be changed in your app.

zjamshidi commented 4 years ago

Thanks a ton. Looking forward to getting the new release

ojw28 commented 4 years ago

This will be in the 2.12.0 release. We don't have a good idea of the date yet, unfortunately.