2013-03-11 16 views
5

Znam wiele pytań dotyczących tego samego problemu, ale po następujących sugestii this one's napotykam na kilka problemów.Jak zapętlić kolejkę dźwięków w AVQueuePlayer?

Mam wszystko skonfigurowane, ale dostaję się do błędów mach za każdym razem, gdy używam kMTTimeZero.

soundQueue = [AVQueuePlayer queuePlayerWithItems:soundEmotions]; 

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

Oto, co zrobiłem.

- (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)

Odpowiedz

17

kCMTimeZero jest symbolem w CoreMedia.framework, dlatego trzeba dodać te ramy do sekcji „Link binarnych z Biblioteki” w „Budowanie fazą” swojego celu.

+0

Dziękujemy! Dodałem framework i gra się dobrze, ale z jakiegoś powodu wciąż nie zapętlał dźwięku. Czy nie robię tego poprawnie? Dzięki! – KingPolygon

+0

Wymyśliłem! Ale dziękuję! – KingPolygon

+0

@KingPolygon, co zrobiłeś, aby utworzyć pętlę AVQueuePlayer? – Raphael

0

Używam tego podejścia do obserwować ostatni element a następnie 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) 
      } 
     } 
    } 

A potem

private func observeTrackChanged(of player : AVQueuePlayer) { 

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