While using next and previous functionality in AudioStreamer, two or more songs starts together

无人久伴 提交于 2019-12-12 04:28:29

问题


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;
}

回答1:


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



来源:https://stackoverflow.com/questions/7453076/while-using-next-and-previous-functionality-in-audiostreamer-two-or-more-songs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!