播放音乐时需要褪色效果

时间:2014-12-17 12:45:59

标签: ios objective-c iphone ipad ios8

在我的应用程序中,我使用iPod播放器播放背景音乐(音乐应用程序),使用AvAudioPlayer播放URL中的歌曲。我想在这些播放器之间切换时为歌曲添加淡化效果。我尝试通过减少一个玩家的音量并增加另一个玩家的方式,但它没有给我褪色效果。谁能帮助我如何实现这一目标? 提前致谢

这是我的代码

- (IBAction)play:(id)sender
{
    timerCount = 0;
    playAndPauseTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(playTimer) userInfo:nil repeats:YES];
}

-(void)playTimer
{
    MPMusicPlayerController *musicPlayer = [MPMusicPlayerController iPodMusicPlayer];

    if(timerCount < 10) {
        timerCount++;

        float volume = musicPlayer.volume;
        if(volume>0) {
            volume = musicPlayer.volume-0.02f;
            [musicPlayer setVolume:volume];
        }
    } else {
        [playAndPauseTimer invalidate];
        [musicPlayer setVolume:initialVolume];
        [audioplayer play];
        pauseButton.hidden = NO;
        startButton.hidden = YES;
    }
}

- (IBAction)pause:(id)sender
{
    //[self pauseTimer];
    timerCount=0;
    playAndPauseTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(pauseTimer) userInfo:nil repeats:YES];

}

-(void)pauseTimer
{
    MPMusicPlayerController *musicPlayer = [MPMusicPlayerController iPodMusicPlayer];

    if(timerCount < 10) {
        timerCount++;

        float volume = musicPlayer.volume;
        if(volume > 0){
            volume = musicPlayer.volume-0.02f;
            [musicPlayer setVolume:volume];
        }
    } else {
        [playAndPauseTimer invalidate];
        [audioplayer pause];
        [musicPlayer setVolume:initialVolume];
        pauseButton.hidden = YES;
        startButton.hidden = NO;
    }
}

0 个答案:

没有答案