开发者

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

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 = [NSUs开发者_如何学运维erDefaults 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;
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜