Reputation: 504
I'm trying to do a small radio app and I got a list of URL that I pass to AVPlayer but I can't understand how to manage different URL.
As example if I first play this URL: http://www.example.com/file.mp3 then I call http://www.example.net/file2.mp3 it works fine but when I select http://www.example.org/file.mp3.m3u it doesn't load that URL and AVPlayer won't play.
This is the code I use:
urlStream = [NSURL URLWithString:mp3URL];
appDelegate = [[UIApplication sharedApplication]delegate];
playerItem = [AVPlayerItem playerItemWithURL:urlStream];
playerItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil];
[playerItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
[appDelegate.player replaceCurrentItemWithPlayerItem:playerItem];
I use replaceCurrentItemWithPlayerItem:playerItem
because if I use initWithPlayerItem
when I choose another stream I just can't stop the previous play: so the only way to stop the playing stream and start another one is to use replaceCurrentItemWithPlayerItem
.
In the Apple documentation I read that replaceCurrentItemWithPlayerItem
must have the same "compositor" as the items it replaces: what's a compositor?
I see that what it's different between the first two streams and the third (in the example above) is the file extension.
Any suggestion where to look for would be greatly appreciated.
Upvotes: 2
Views: 3791
Reputation: 137
The problem appears not to be the replacing of items - but the file format of particular files. Try to open the m3u file first - probably it will fail as well.
The m3u-URL indicates that this not an mp3 file but a m3u file - that's a list of URLs to media files. AVPlayer
and AVPlayerItem
are capable of playing m3u8 files - that are m3u files which are UTF8-encoded.
Have you tried opening those URLs in Mobile Safari? If they don't work there the format probably is not supported by AVPlayer
either.
In any case - if you could provide the actual problematic URL one could check the actual file format.
With "compositor" the "Quartz compositor" is meant - forget about that, not relevant here. [Edit: maybe it is relevant - I'm dumbfounded after you comment to this answer ...]
Upvotes: 2