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

Redownload audio file from source #1348

Open
lakecountypassage opened this issue May 6, 2024 · 7 comments
Open

Redownload audio file from source #1348

lakecountypassage opened this issue May 6, 2024 · 7 comments
Assignees
Labels

Comments

@lakecountypassage
Copy link

I have an mp3 file that get's updated at the source every few minutes. On my end, the URL/URI is the same, but the audio file changes (text to speech audio).

If I am playing the file on repeat: player.setRepeatMode(Player.REPEAT_MODE_ONE).

How can I get ExoPlayer or MediaSessionService to redownload the file from the source?

It doesn't even matter if it's on repeat, I am using a MediaSessionService so it's loaded the file in the background. I need to redownload or reload or refresh the audio.

I am guessing I will need to use the DownloadService (https://developer.android.com/media/media3/exoplayer/downloading-media). I'd rather not add the complication for this if there's any alternatives. It's a feature of our app they may never or rarely get used, but we want support for it.

Thanks for your help.

@lakecountypassage
Copy link
Author

I have an mp3 file that get's updated at the source every few minutes. On my end, the URL/URI is the same, but the audio file changes (text to speech audio).

If I am playing the file on repeat: player.setRepeatMode(Player.REPEAT_MODE_ONE).

How can I get ExoPlayer or MediaSessionService to redownload the file from the source?

It doesn't even matter if it's on repeat, I am using a MediaSessionService so it's loaded the file in the background. I need to redownload or reload or refresh the audio.

I am guessing I will need to use the DownloadService (https://developer.android.com/media/media3/exoplayer/downloading-media). I'd rather not add the complication for this if there's any alternatives. It's a feature of our app they may never or rarely get used, but we want support for it.

Thanks for your help.

My best attempt to make this work, is to force the player to get a new item. Thoughts?

    player.addListener(new Player.Listener() {
        @Override
        public void onPlaybackStateChanged(int playbackState) {
            Player.Listener.super.onPlaybackStateChanged(playbackState);
            if(playbackState == player.STATE_ENDED){
                player.removeMediaItem(0);
                player.setMediaItem(mediaItem);
                player.prepare();
                player.play();
            }
        }
    });

@icbaker icbaker self-assigned this May 7, 2024
@icbaker
Copy link
Collaborator

icbaker commented May 8, 2024

If I am playing the file on repeat: player.setRepeatMode(Player.REPEAT_MODE_ONE).

How can I get ExoPlayer or MediaSessionService to redownload the file from the source?

By default, ExoPlayer will re-load the file on every repeat - that's what I observe in the demo app (I added some logging to DefaultDataSource.open).

Please could you clarify exactly what you observe?

@lakecountypassage
Copy link
Author

It's hard for me to tell, I need to test again. I did notice when tracing the internet traffic through Android Studio that on repeat (when the audio started again) there was no corresponding network traffic.

@lakecountypassage
Copy link
Author

@icbaker how do you know it's supposed to re-load on repeat? I couldnt find anything in the source to say/show that's what's happening. There was another post I found that said it was behaving that way, but I couldnt replicate their findings.

@icbaker
Copy link
Collaborator

icbaker commented May 16, 2024

I did notice when tracing the internet traffic through Android Studio that on repeat (when the audio started again) there was no corresponding network traffic.

I would expect to see the network traffic happen when the data is loaded, which generally won't be at the same time as it's played, due to buffering - so what you've described here doesn't sound like it proves the file isn't being re-loaded for each repeat. By default ExoPlayer buffers 50s ahead of the playback position (and this extends into 'future' playlist items, including repeats, to avoid pausing to re-buffer at item transitions). For example, this means that if you repeat a 5s item, I'd expect you to see about 10 loads immediately after starting playback. Whereas if you repeat a 1min item, I'd expect you to see a single load at the start of playback, then another one 10s into playback (1min - 50s).


how do you know it's supposed to re-load on repeat?

As I mentioned above, I added logging in DefaultDataSource.open, and saw this occur repeatedly in the logs when playing a short item on repeat in the demo app.

@lakecountypassage
Copy link
Author

Thank you. I'm an idiot, where are you finding that method? @icbaker. The only issue I see with pre-loading is that you may be loading the file well before you need the update. However, my audio is ~2min long so you're saying there might a reload of data ~50 sec ahead of when it's done playing? That's not too bad.....

@icbaker
Copy link
Collaborator

icbaker commented May 17, 2024

Thank you. I'm an idiot, where are you finding that method?

public long open(DataSpec dataSpec) throws IOException {


However, my audio is ~2min long so you're saying there might a reload of data ~50 sec ahead of when it's done playing? That's not too bad.....

The 50s is only a default, you can customize it by providing a custom LoadControl (probably an instance of DefaultLoadControl) when you build the player.

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

No branches or pull requests

3 participants