2013-03-11 65 views
5

我知道存在關於同一問題的多個問題,但在遵循this one's建議之後,我遇到了一些問題。如何循環播放AVQueuePlayer中的聲音隊列?

我已經設置了一切,但每次使用kMTTimeZero時都會遇到mach錯誤。

soundQueue = [AVQueuePlayer queuePlayerWithItems:soundEmotions]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(playerItemDidReachEnd:) 
               name:AVPlayerItemDidPlayToEndTimeNotification 
               object:[soundEmotions lastObject]]; 

這就是我所做的。

- (void)playerItemDidReachEnd:(NSNotification *)notification { 
    // Do stuff here 
    NSLog(@"End has been reached."); 

    // Set it back to the beginning 
    [soundQueue seekToTime:kCMTimeZero]; 

    //Replay 
    [soundQueue play]; 

} 

ERROR: Undefined symbols for architecture armv7: "_kCMTimeZero", referenced from: -[ViewController playerItemDidReachEnd:] in ViewController.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

回答

17

kCMTimeZero是在CoreMedia.framework的象徵,因此,你要這個框架添加到「鏈接二進制與圖書館」一節中的「構建階段」的目標。

+0

謝謝!我添加了框架,它構建得很好,但由於某種原因,它仍然沒有循環播放聲音。我沒有做對嗎?謝謝! – KingPolygon 2013-03-11 19:30:05

+0

我想通了!謝謝你! – KingPolygon 2013-03-11 19:52:08

+0

@KingPolygon,你做了什麼使AVQueuePlayer循環? – Raphael 2014-11-18 15:21:23

0

我使用這種方法來觀察最後一個項目然後seek to kCMTimeZero

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { 

     if keyPath == "currentItem" { 

      print("Next Track...", currentTrackIndex) 

      if currentTrackIndex > 0 { 
       self.isPlaying = true 
      } 

      currentTrackIndex += 1 
      if currentTrackIndex > playerQueue.items().count { 
       currentTrackIndex = 0 
       playerQueue.seek(to: kCMTimeZero) 
      } 
     } 
    } 

然後

private func observeTrackChanged(of player : AVQueuePlayer) { 

     player.addObserver(self, forKeyPath: "currentItem", options: .new, context: nil) 
    }