这是下一个和上一个按钮的代码
- (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
player=@"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
player=@"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;
}