1

Recently i have started working on iOS application development. These days i am working on a Music Player which must have following functionality:

-Online buffering of the song from php web service. -Play, pause, stop, next song, previous song. -two sliders, one is for volume control and other is for showing the play time of the song. -shuffle, repeat song.

I have tried these things with AVPlayer and AVAudioPlayer but in AVAudioPlayer it is not possible to stream the data from url i think because i have tried a lot then i done this by using AVplayer but it is not supporting options like volume control etc. and even the buffering is also not proper like a have to press play button again if the buffering stops at some point. I need an urgent help for this Audio Player any tutorial any example which i can understand easily as i am new in this field. Here is the code

NSURL *url = [[NSURL alloc] initWithString:@"http://www.androidmobiapps.com/extrememusic/app/songs/1.mp3"];

[self setupAVPlayerForURL:url];

I am calling this song at viewdidload

-(void) setupAVPlayerForURL: (NSURL*) url {
AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset];

audioPlayer = [AVPlayer playerWithPlayerItem:anItem];
[audioPlayer addObserver:self forKeyPath:@"status" options:0 context:nil];

}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

if (object == audioPlayer && [keyPath isEqualToString:@"status"]) {
    if (audioPlayer.status == AVPlayerStatusFailed) {
        NSLog(@"AVPlayer Failed");
    } else if (audioPlayer.status == AVPlayerStatusReadyToPlay) {
        NSLog(@"AVPlayer Ready to Play");
    } else if (audioPlayer.status == AVPlayerItemStatusUnknown) {
        NSLog(@"AVPlayer Unknown");
    }
}

}

Atul
  • 111
  • 3
  • 12

1 Answers1

0

I've done functions you mentioned above as a class, and open source it. Whatever you wanna use the class directly or treat it as an AVFoundation beginner examples. Good luck!

Watch this repo on GitHub here

saiday
  • 1,290
  • 12
  • 25