在 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
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;
}
Here is the code for next and previous button
- (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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AudioStreamer 类存在与流式传输期间暂停相关的错误。因此 gitHub 上给出了一篇很好的文章来解决这个问题。
AudioStreamer class has a bug related to Pause during streaming. So a nice post is given on gitHub to solve this problem.