ios - Need to stop AVPlayer before playing new stream -


i have on-line radio app. located on first viewcontroller (tableview) audio streams. audio streams made table. clicking on name of stream screen opens avpalyer. problem when opening second stream, ашкые stream played simultaneously. how make played if 1 thread, , second turned down?

avplayer:

@interface radioviewcontroller ()  @end  @implementation radioviewcontroller  - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) {     // custom initialization } return self; }  - (void)viewdidload {   [super viewdidload];  // additional setup after loading view. nsstring *restorationid = self.restorationidentifier; nsstring *streamid = _detail.label; nsstring* identifer = [restorationid stringbyappendingstring: streamid]; nslog(@"%@", identifer);   self.title = apptitle; self.streamlabel.text = _detail.label; //Определение потока  nsstring *streamurl;  if (_detail.label == @"ПЕРВЫЙ"){     streamurl = streamurlpervyj; } if (_detail.label == @"РОК") {     streamurl = streamurlrok; } if (_detail.label == @"БИТ") {     streamurl = streamurlbit; } if (_detail.label == @"ПО-РУССКИ") {     streamurl = streamurlporusski; } if (_detail.label == @"ХИП-ХОП") {     streamurl = streamurlhiphop; } if (_detail.label == @"РЕЛАКС") {     streamurl = streamurlrelax; } if (_detail.label == @"РЕТРО") {     streamurl = streamurlretro; }      if(![self connected]) {         uialertview *alert = [[uialertview alloc] initwithtitle:@"Невозможно установить соединение" message:@"Проверьте соединение с интернетом" delegate:self cancelbuttontitle:@"ОК" otherbuttontitles: nil];         [alert show];     } else {         //start stream         avplayeritem* playeritem = [avplayeritem playeritemwithurl:[nsurl urlwithstring:streamurl]];         [playeritem addobserver:self forkeypath:@"timedmetadata" options:nskeyvalueobservingoptionnew context:nil];         music = [avplayer playerwithplayeritem:playeritem];         [music play];     }   [[nsnotificationcenter defaultcenter] addobserver:self                                          selector:@selector(playbutton:)                                              name:@"toggleplaypause"                                            object:nil];  //set title view titleview = [[uilabel alloc] initwithframe:cgrectmake(0, 240, myscrollview.frame.size.width, 40)]; [self setstyle]; //set style layers titleview.text = @"Подключаюсь..."; cgfloat textlength = titleview.intrinsiccontentsize.width; [myscrollview addsubview: titleview]; [self.view addsubview:myscrollview]; if (textlength < 240) {     [self centertext]; }   timer = [nstimer scheduledtimerwithtimeinterval:(1.0/2.0) target:self   selector:@selector(timed) userinfo:nil repeats:yes];   } 

http://dev.b4u.by/radio.jpg

you can decleare avplayer object "music" in appdelegate access way

appdelegate *maindelegate = [uiapplication sharedapplication].delegate; [maindelegate.music pause]; maindelegate.music = nil; 

when want start new stream or before alloc init


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -