簡體   English   中英

滑塊在播放音頻結束時停止

[英]Slider stop at the end of playing audio

在我的項目中,我正在使用AVAudioPlayer播放保存的音頻。我正在顯示用於播放音頻的滑塊。 使用播放器的當前時間屬性設置滑塊的值。 playSlider.value = avAudioPlayer.currentTime; 這是計時器代碼

updateTimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(updateCurrentTime) userInfo:p repeats:YES];



//Calls the update current time function 
- (void)updateCurrentTime
{
    [self updateCurrentTimeForPlayer:self.player];
}


//Updates the current time while the audio is playing
-(void)updateCurrentTimeForPlayer:(AVAudioPlayer *)avAudioPlayer
{
    currentTimeLabel.text = [NSString stringWithFormat:@"%d:%02d", (int)avAudioPlayer.currentTime / 60, (int)avAudioPlayer.currentTime % 60, nil];
    playSlider.value = avAudioPlayer.currentTime;

    if (playSlider.value==playSlider.minimumValue) 
    {
        moveToBeginningButton.enabled = NO;
        rewindButton.enabled = NO;
        NSLog(@"PlaySliderMaxValue1 === %f",playSlider.maximumValue);
        NSLog(@"PlaySliderValue1 === %f",playSlider.value);
    }
    else  
    {  
        moveToBeginningButton.enabled = YES;
        rewindButton.enabled = YES; 
        NSLog(@"PlaySliderMaxValue2 === %f",playSlider.maximumValue);
        NSLog(@"PlaySliderValue2 === %f",playSlider.value);

    }
}

滑塊的最大值設置如下

playSlider.maximumValue = audioPlayer.duration;

我遇到的問題是播放后滑點始終會返回音頻的開頭,這是一個錯誤嗎? 我該如何更改? 請提供您的建議。

在將其分配給playlider.value之前,先打印avAudioPlayer.currentTime的值,我認為最后它會變為零。 它將為playslider.value分配零

我不能說這是否是一個錯誤,但是請嘗試使用AVAudioPlayer委托方法。 didFinishPlaying方法中,將Slider值設置為maximumValue。 這可能是解決方案之一。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM