在 AudioStreamer 中使用下一首和上一首功能时,两首或多首歌曲同时开始

发布于 2024-12-05 08:05:45 字数 2525 浏览 2 评论 0原文

这是下一个和上一个按钮的代码

- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潇烟暮雨 2024-12-12 08:05:45

AudioStreamer 类存在与流式传输期间暂停相关的错误。因此 gitHub 上给出了一篇很好的文章来解决这个问题。

AudioStreamer class has a bug related to Pause during streaming. So a nice post is given on gitHub to solve this problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文