Swift AVAudioPlayer wont play audio recorded with AVAudioRecorder

后端 未结 2 545
离开以前
离开以前 2021-01-17 00:18

I have built an app that records an audio clip, and saves it to a file called xxx.m4a.

Once the recording is made, I can find this xxx.m4a

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-17 01:05

    You playing code is fine; your only problem is with the scope of your AVAudioPlayer object. Basically, you need to keep a strong reference to the player around all the time it's playing, otherwise it'll be destroyed by ARC, as it'll think you don't need it any more.

    Normally you'd make the AVAudioPlayer object a property of whatever class your code is in, rather than making it a local variable in a method.

提交回复
热议问题