代码之家  ›  专栏  ›  技术社区  ›  KingPolygon

如何在AVQueuePlayer中循环声音队列?

  •  5
  • KingPolygon  · 技术社区  · 12 年前

    我知道同一问题存在多个问题,但在以下内容之后 this one's 建议,我遇到了几个问题。

    我已经设置好了一切,但每次使用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];
    
    }
    

    错误:体系结构armv7的未定义符号:“_kCMTimeZero”, 引用自: -ViewController中的[ViewController playerItemDidReachEnd:]。o ld:未找到体系结构armv7 clang:错误:链接器的符号 命令失败,退出代码为1(使用-v查看调用)

    2 回复  |  直到 8 年前
        1
  •  17
  •   Martin R    12 年前

    kCMTimeZero 是中的一个符号 核心媒体框架 ,因此您必须将此框架添加到目标的“构建阶段”中的“将二进制与库链接”部分。

        2
  •  0
  •   Michał Ziobro    7 年前

    我正在使用这种方法 观察最后一项 然后 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)
        }