Skip to content
New issue

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

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

Already on GitHub? # to your account

Can ExoPlayer play gapless looping audio? #920

Closed
boywithk9 opened this issue Nov 3, 2015 · 7 comments
Closed

Can ExoPlayer play gapless looping audio? #920

boywithk9 opened this issue Nov 3, 2015 · 7 comments
Labels

Comments

@boywithk9
Copy link

We have looping background sounds in our apps, and with the Android mediaplayer, there's a noticeable gap when the audio files loop. We've tried both m4a and ogg audios, but the gap is always there. Does ExoPlayer eliminate these gaps?

@ojw28 ojw28 added the question label Nov 3, 2015
@andrewlewis
Copy link
Collaborator

There is currently no simple way to achieve this with ExoPlayer: for gapless playback it is necessary to read the relevant metadata from source, trim decoded audio samples from the start/end of the presentation based on the metadata and use the same Android AudioTrack instance across the transition from one source to the next. #497 tracks adding support for doing this.

(Note that the Android framework's MediaPlayer has a method setNextMediaPlayer which might work for your use case, but this is unrelated to ExoPlayer so we can't provide support here.)

@boywithk9
Copy link
Author

Thanks for your reply. Just to be clear, this is for looping a single audio file, not sequential playback of multiple audio files. It seems like your reply might be based on a misunderstanding that it was for sequential audio files. Does that make a difference? It's hard to believe it's so difficult to prevent gaps in looped audio on Android. On iOS, it's automatic.

Thanks

Sent from my iPhone

On Jan 13, 2016, at 4:20 AM, Andrew Lewis notifications@github.com wrote:

There is currently no simple way to achieve this with ExoPlayer: for gapless playback it is necessary to read the relevant metadata from source, trim decoded audio samples from the start/end of the presentation based on the metadata and use the same Android AudioTrack instance across the transition from one source to the next. #497 tracks adding support for doing this.

(Note that the Android framework's MediaPlayer has a method setNextMediaPlayer which might work for your use case, but this is unrelated to ExoPlayer so we can't provide support here.)


Reply to this email directly or view it on GitHub.

@andrewlewis
Copy link
Collaborator

I don't think it makes any difference. In the current design, you can implement looping by seeking back to the start of the stream when playback ends, but this won't be gapless because the player can't prepare what will be played next in advance. Also, we don't currently trim encoder delay/padding samples, which means the output will include silence at the start/end of playback for streams that use this.

For now, I'd probably just use MediaPlayer.setNextMediaPlayer. If you need to use ExoPlayer for some reason and you know that the input media does not use encoder delay and padding, it might be possible to implement gapless looping using a custom concatenating SampleSource specialized to your use case, perhaps using #1070 as a starting point.

@andrewlewis
Copy link
Collaborator

We now extract and apply gapless playback metadata (see #497). Playlist support in #1270 will make this easy to use (including for looping).

@Flyview
Copy link

Flyview commented Apr 9, 2016

Will the gapless support also work for video? Specifically looping the same
video without a gap.
On Apr 9, 2016 10:05 AM, "Andrew Lewis" notifications@github.com wrote:

We now extract and apply gapless playback metadata (see #497
#497). Playlist support in
#1270 #1270 will make this
easy to use (including for looping).


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#920 (comment)

@andrewlewis
Copy link
Collaborator

It's still work in progress, but I think video transitions should be seamless.

@dmota-systango
Copy link

You can use LoopingMediaSource as source instead.

MediaSource source = new ExtractorMediaSource(videoUri, ...);
// Loops the video indefinitely.
LoopingMediaSource loopingSource = new LoopingMediaSource(source);

Ref: https://google.github.io/ExoPlayer/guide.html#seamlessly-looping-a-video

@google google locked and limited conversation to collaborators Jun 28, 2017
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants