Arjun Sa
Arjun Sa

Reputation: 125

how to play mp3 in asset url using AVPlayer

i have url in ipod-library://item/item.mp3?id=8788117795090152241 how to play mp3 in this url

   AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url_selectedSong];
AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
[player play];

but not play song

Upvotes: 1

Views: 841

Answers (1)

Sujith Thankachan
Sujith Thankachan

Reputation: 3506

Use this:

NSError * error;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];

if(player) {
    [player play];
}

Upvotes: 1

Related Questions