start playing audio from a background task via AVAudioPlayer in Xcode

前端 未结 5 1004
小鲜肉
小鲜肉 2021-02-03 14:46

I am trying to start playing a sound from a background task via an AVAudioPlayer that is instantiated then, so here\'s what I\'ve got.

For readability I cut out all user

5条回答
  •  不思量自难忘°
    2021-02-03 15:02

    include your playSoundFile call in the below, this should always run it in main thread

    dispatch_async(dispatch_get_main_queue(), ^{
    
    });
    

    add this if to your - (void) playSoundFile to check if player is created, if not, then create it

    if(!_player) {
        _player = [[AVQueuePlayer alloc] init];
    }
    

提交回复
热议问题