2013-03-11 14 views
5

So che esistono più domande relative allo stesso problema, ma dopo aver seguito i suggerimenti this one's, ho riscontrato un paio di problemi.Come si esegue il ciclo della coda di suoni in AVQueuePlayer?

Ho tutto configurato, ma riesco a errori mach ogni volta che uso kMTTimeZero.

soundQueue = [AVQueuePlayer queuePlayerWithItems:soundEmotions]; 

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

Ecco cosa ho fatto.

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

risposta

17

kCMTimeZero è un simbolo nel CoreMedia.framework, pertanto è necessario aggiungere questo quadro la sezione "collegamento binari con le librerie" nel "costruire" Fasi del vostro target.

+0

Grazie! Ho aggiunto il framework e lo sviluppo è perfetto, ma per qualche motivo continua a non riprodurre il suono. Non lo sto facendo correttamente? Grazie! – KingPolygon

+0

L'ho capito! Grazie comunque! – KingPolygon

+0

@KingPolygon, che cosa hai fatto per rendere il ciclo AVQueuePlayer? – Raphael

0

Sto usando questo approccio alla osservare ultimo elemento e poi 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) 
      } 
     } 
    } 

E poi

private func observeTrackChanged(of player : AVQueuePlayer) { 

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