2011-09-17 45 views
0

這裏是下一個和以前按鈕的代碼雖然AudioStreamer未來和以前使用的功能,兩個或更多的歌曲開始一起

- (IBAction)nextPressed:(id)sender 
{ 
    Previousbutton.enabled=YES; 
    Nextbutton.enabled = NO; 
    NSLog(@"TOTAL TRACK:%d",TotalTrackCount); 
    // TrackCount = TotalTrackCount+1; 
    if(selectedIndex+1 < TotalTrackCount) 
    { 
     [streamer stop]; 
     [self performSelector:@selector(destroyStreamer) ] ; 
     //player flag 
     [email protected]"stop"; 

     int new_index; 
     new_index=selectedIndex+1; 
     selectedIndex=new_index; 
     str_AudioUrl=[array_audioUrl objectAtIndex:selectedIndex]; 
     userPrefs = [NSUserDefaults standardUserDefaults]; 
     [userPrefs setInteger:new_index forKey:@"Index"]; 
     str_AudioUrl=[array_audioUrl objectAtIndex:new_index]; 

     [self performSelector:@selector(createStreamer) ] ; 
     //[self setButtonImage:[UIImage imageNamed:@"loadingbutton.png"]]; 
     [streamer start]; 

     NSString *newtitle=[array_AudioName objectAtIndex:new_index]; 
     self.title=newtitle; 
     NSLog(@"selected index next==%d",selectedIndex); 
     [self performSelector:@selector(enableNext) withObject:nil afterDelay:2.0]; 
    } 
    else { 
     Nextbutton.enabled=NO; 
    } 
} 

- (void) enableNext 
{ 
    Nextbutton.enabled = YES; 
} 

//it will play next sone from table (next index) 
- (IBAction)previousPressed:(id)sender 
{ 
    Nextbutton.enabled = YES; 
    Previousbutton.enabled = NO; 
    NSLog(@"selected index previous==%d",selectedIndex); 

    if(selectedIndex >0) 
    { 
     [streamer stop]; 

     //player flag 
     [email protected]"stop"; 
     [self performSelector:@selector(destroyStreamer) ] ; 

     int new_index; 
     new_index=selectedIndex-1; 
     selectedIndex=new_index; 
     str_AudioUrl=[array_audioUrl objectAtIndex:selectedIndex]; 
     userPrefs = [NSUserDefaults standardUserDefaults]; 
     [userPrefs setInteger:new_index forKey:@"Index"]; 
     str_AudioUrl=[array_audioUrl objectAtIndex:new_index]; 

     [self performSelector:@selector(createStreamer)] ; 
     [self setButtonImage:[UIImage imageNamed:@"loadingbutton.png"]]; 
     [streamer start]; 

     NSLog(@"selected index previous2==%d",selectedIndex); 
     NSString *newtitle=[array_AudioName objectAtIndex:new_index]; 
     self.title=newtitle; 
     [self performSelector:@selector(enablePrevious) withObject:nil afterDelay:2.0]; 
    } 
    else { 
     Previousbutton.enabled = NO; 
    } 
} 

- (void) enablePrevious 
{ 
    Previousbutton.enabled = YES; 
} 

回答

0

AudioStreamer類有流期間暫停相關的錯誤。所以在gitHub上給出了一個很好的帖子來解決這個問題。

相關問題