UISlider to control AVAudioPlayer

后端 未结 4 1135
执笔经年
执笔经年 2020-12-01 03:40

I\'m trying to implement a little function in my app. I am currently playing sounds as AVAudioPlayers and that works fine. What I would like to add is to control the sound\'

4条回答
  •  臣服心动
    2020-12-01 04:05

    I needed to adapt the above answer a bit to get it to work. The issue is that using

    slider.maximumValue = [player duration];
    slider.value = player.currentTime;
    player.currentTime = slider.value;
    

    Do not work because the slider expects a float and the player currentTime and dration return CMTime. To make these work, I adapted them to read:

    slider.maximumValue = CMTimeGetSeconds([player duration]);
    slider.value = CMTimeGetSeconds(player.currentTime);
    player.currentTime = CMTimeMakeWithSeconds((int)slider.value,1);
    

提交回复
热议问题