AVPlayer is not playing audio

后端 未结 1 582
野的像风
野的像风 2021-01-27 23:29

I am trying to play a url audio file picked with MPMediaPickerController and attach an observer on the player object. I don\'t know why the player is n

相关标签:
1条回答
  • 2021-01-28 00:24

    You should declare AVPlayer as a global variable inside your class/struct. So, remove player from addPeriodicTimeObserver function and declare globally.

    The reason behind this is:

    Local variables (variables declared inside the function) get deallocated once the function returns; In this case, player gets deallocated before even playing.

    Instance variables (variables declared inside the class scope) get deallocated once the class instance get deallocated (unless there is a retain cycle).

    In case of using a real device for testing, make sure that its not in silent mode

    0 讨论(0)
提交回复
热议问题