Audio streaming in ios using AVPlayer -


i trying develop small app should stream audio particular link. using avplayer dont know why not working. tried google nothing seems relevant there. kindly help.. thank you

- (void)viewdidload { [super viewdidload];  nsurl *url = [nsurl urlwithstring:@"http://108.166.161.206:8826/stream.mp3"];  self->playeritem = [avplayeritem playeritemwithurl:url]; self->player = [avplayer playerwithplayeritem:playeritem]; self->player = [avplayer playerwithurl:url]; [player play];  } 

don`t know why first init player playeritem , after init nsurl. anyways, here way go:

-(void) viewdidload{      player = [[avplayer alloc] initwithurl:              [nsurl urlwithstring:@"http://xxx/yourfile.mp3"]];      [player addobserver:self forkeypath@"status" options:0 context:nil]; }  - (void) observevalueforkeypath:(nsstring *)keypath                                  ofobject:(id)object                                  change:(nsdictionary  *)change                                  context:(void *)context {      if (object == player && [keypath isequaltostring:@"status"]) {         if (player.status == avplayerstatusreadytoplay) {             [player play];         }         if (player.status == avplayerstatusfailed) {             nslog(@"something went wrong: %@", player.error);         }     } } 

the av foundation programming guide should start point find out how avplayer stuff works


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -