AVAudioEngine seek the time of the song

前端 未结 2 1463
北荒
北荒 2021-02-06 12:33

I am playing a song using AVAudioPlayerNode and I am trying to control its time using a UISlider but I can\'t figure it out how to seek the time using

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-06 13:09

    For future readers, probably better to get the sample rate as :

    playerNode.outputFormat(forBus: 0).sampleRate

    Also take care when converting to AVAudioFramePosition, as it is an integer, while sample rate is a double. Without rounding the result, you may end up with undesirable results.

    P.S. The above answer assumes that the file you are playing has the same sample rate as the output format of the player, which may or may not be true.

提交回复
热议问题