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

Playing AAC stream #227

Closed ganeshjay closed 9 years ago

ganeshjay commented 9 years ago

I am trying to play an AAC stream using exoplayer demo. I have only changed the url and not been successful so far. Any help would be appreciated. It always get stuck in the MediaExtractor setDatasource method

1) URL 1 - http://streamcdn.atc-labs.com/AtcStream128.aac This throws an error could not at detect media content at the setDatasource method. 2) URL 2 - http://sc.powergroup.com.tr:80/PowerFM/aac/128/tunein This is not exiting the setDatasource method and keeps reading the stream.

It works for other types of streams.

ojw28 commented 9 years ago
ojw28 commented 9 years ago

Correction - It looks like it should be possible to support seeking (since the platform extractor does it).

ojw28 commented 9 years ago

Heh. It actually looks like the platform extractor scans through the entire stream to construct an index for seeking. Which is perhaps why it appears to get stuck (this is conjecture). In any case, it appears seeking should not be supported after all.

ganeshjay commented 9 years ago

Seeking is not required, since it is a internet radio broadcast. I suspect it is trying to scan the entire thing to get some media information and since it is continuous stream it gets stuck. Any fix for this will be greatly appreciated.

ojw28 commented 9 years ago

I have this more or less working, but it seems like this is fundamentally a bad way to stream audio, particularly to mobile devices.

The client opens a network connection, starts streaming audio, and everything is fine. But what's the client supposed to do when it encounters a network error (which is highly likely over a long period of time on a mobile device, since it may well be switching between WiFi/mobile, or just on a flaky mobile connection etc). It seems like it's impossible for the client to request data starting from exactly where it encountered the error, meaning it's impossible to seamlessly recover from any network error.

Furthermore, it appears to be impossible to distinguish between a live AAC stream such as the PowerFM example, and a non-live AAC file. Desired retry behavior is different in each case, because for the non-live AAC file you want to make a range request starting where you left off, where-as for the live case you want to request starting from a 0 byte offset.

Is that correct? Am I missing something? If I am correct, how exactly is this ever supposed to work nicely on a mobile device, unless it's stationary with a solid WiFi connection?

mingfai commented 9 years ago

just a note that my use case in #389 is, as same as @ganeshjay, for Internet radio broadcast. for this use case, I would argue freshness is more important than seamless recovery. The host may run a live event such as phone-in, or making comment on a live event, a prolonged delay is odd. If the connection is interrupted for 10s or any long enough duration, I actually wish the player just skip the 10s rather than attempting any recovery.

there are other cases that a seamless recovery is preferred, say, for playing movie or TV series. Could ExoPlayer give an option for developer to choose between the two kinds of usage?

ganeshjay commented 9 years ago

Since this is an internet radio broadcast there is no need and now way to resume from where the error occurred nor any way to seek etc. You can only listen from when you tune in. It should resume from where the broadcast is currently streaming like you said from 0 byte offset. It is different from on demand music or video.

ojw28 commented 9 years ago
ganeshjay commented 9 years ago

Thanks for really analyzing the problem in detail and coming up with a solution. This would be of really useful for us.

ojw28 commented 9 years ago

This should all work nicely now. For URL (2) in the original report, use TYPE_MP3 in the demo app. It should play nicely, and resume properly when errors occur (unless the outage is extended, in which case the application will be notified of the error). URL (1) doesn't seem to be up any more.

Separately, we're aware that it might be a bit painful to have to know the type of the media prior to playback. We'll be looking at sniffing the format automatically at some point (possibly not particularly soon though).