ios - In AVAudioplayer multiple songs play at once.how to fix single song play at a time -


i trying create avaudioplayer programatically.the audio player playing.but have issues.i displaying 12 audio items in uitableview.if click first item should navigate audio player view controller.and click play button song play.if click button song play continuously.but if click again same item audio view controller view display initial state progress bar should not move , current time , song duration empty.but song play continuously. , issue there. if click first item corresponding song play.i should not click pass button.i click button , click second item.if click second item audio view controller display.i click play button song display.in background first song play , second song play.this second issue.how solve these 2 issues.please me body.

-(void)playorpausebuttonpressed:(id)sender {     if(playing==no)     {         [playbutton setbackgroundimage:[uiimage imagenamed:@"pause.png"] forstate:uicontrolstatenormal];         // here pause.png image showing pause button.         nserror *err=nil;         avaudiosession *audiosession=[avaudiosession sharedinstance];         [audiosession setcategory:avaudiosessioncategoryplayback error:nil];         nslog(@"%@ %d",urlsarray,selectedindex);         nsstring *sourcepath=[urlsarray objectatindex:selectedindex];         nsdata *objectdata=[nsdata datawithcontentsofurl:[nsurl urlwithstring:sourcepath]];         audioplayer = [[avaudioplayer alloc] initwithdata:objectdata error:&err];         audioplayer.numberofloops = 0;         [audioplayer preparetoplay];         audioplayer.delegate=self;         [audioplayer play];         playing=yes;     }     else if (playing==yes)     {         [playbutton setbackgroundimage:[uiimage imagenamed:@"play.png"] forstate:uicontrolstatenormal];         [audioplayer pause];         playing=no;     }     if (self.audioplayer)     {         [self updateviewforplayerinfo];         [self updateviewforplayerstate];         [self.audioplayer setdelegate:self];     } } -(void)updateviewforplayerinfo {     self.songduration.text = [nsstring stringwithformat:@"%d:%02d", (int)self.audioplayer.duration / 60, (int)self.audioplayer.duration % 60, nil];     nslog(@"%f", self.audioplayer.duration);     self.progressbar.maximumvalue = self.audioplayer.duration;     self.volumeslider.value = self.audioplayer.volume; } -(void)updateviewforplayerstate {     [self updatecurrenttime];     if (self.updatedtimer)     {         [self.updatedtimer invalidate];     }     if (self.audioplayer.playing)     {         self.updatedtimer = [nstimer scheduledtimerwithtimeinterval:0.01 target:self selector:@selector(updatecurrenttime) userinfo:self.audioplayer repeats:yes];     } } -(void)updatecurrenttime {     //nslog(@"self.audioplayer.currenttime = %f", self.audioplayer.currenttime);     self.currenttime.text = [nsstring stringwithformat:@"%d:%02d", (int)self.audioplayer.currenttime / 60, (int)self.audioplayer.currenttime % 60, nil];     self.progressbar.value = self.audioplayer.currenttime; } -(void)volumeslidermoved:(uislider *)sender {     self.audioplayer.volume=[sender value]; } 

i think problem here

audioplayer = [[avaudioplayer alloc] initwithdata:objectdata error:&err]; 

each time creating audioplayer object. suggestion check audioplayer before creating object this

if(audioplayer) { audioplayer.delegate=nil; audioplayer=nil; } 

then create object.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -