2017-06-03 3 views
0

J'ai un problème avec la lecture de la file d'attente de la chanson locale (enregistrée sur l'appareil). J'utilise ce cocoapod - https://github.com/tumtumtum/StreamingKit. Mon premier élément dans la file d'attente commence à jouer une fois de plus après sa fin. Il a le statut stopReason AUCUNStreamingKit répète la chanson ios

func audioPlayer(_ audioPlayer: STKAudioPlayer, didFinishPlayingQueueItemId queueItemId: NSObject, with stopReason: STKAudioPlayerStopReason, andProgress progress: Double, andDuration duration: Double) { 

    if stopReason == .eof || stopReason == .pendingNext { 
     checkNextTrack() 
    } 

    if stopReason == .none { 
     print("NONE") 
    } 

    if stopReason == .error || stopReason == .userAction || stopReason == .disposed { 
     stop() 
     resetAudioPlayer() 
    } 
} 

Autres éléments a Statuts de .eof ou .pendingNext et ce comportement est correct. Que dois-je faire dans ce cas? Toutes les URL distantes sont correctement lues. Thnx!

MISE À JOUR: Queue création

internal func playWithQueue(queue: [Song], index: Int = 0) { 
    var audioListNew = [AudioItem]() 
    for (index, value) in queue.enumerated() { 
     let audioItem = AudioItem(audioItem: value, audioIndex: index) 
     audioListNew.append(audioItem) 
    } 

    guard index >= 0 && index < audioListNew.count else { return } 
    newQueue(queue: audioListNew, index: index) 
} 


func newQueue(queue: [AudioItem], index: Int = 0) { 
    self.queue = queue 
    audioPlayer.clearQueue() 

    if let currentSong = self.queue[index].audioItem { 
     play(file: currentSong) 

     for (songIndex, _) in queue.enumerated() { 
      audioPlayer.queue((queue[Int((index + songIndex) % queue.count)].audioItem?.songRealUrl)!) 
     } 

    } 

    currentIndex = index 
} 
+0

Hey. Est-ce que votre premier objet est joué une fois de plus après qu'il soit terminé sans raison ou parce que vous avez fait la queue pour jouer après tout le reste? – tumtumtum

+0

@tumtumtum Sans raison. Je peux vous donner une partie de mon code lorsque je crée une file d'attente. Peut-être que je fais quelque chose de mal –

+0

@tumtumtum Mis à jour ma question –

Répondre

0

j'ai le même problème et je le résoudre! Vous devez faire qch comme ça:

-(void) audioPlayer:(STKAudioPlayer*)audioPlayer didFinishBufferingSourceWithQueueItemId:(NSObject*)queueItemId 
{ 
    SampleQueueId* queueId = (SampleQueueId*)queueItemId; 

    NSLog(@"Requeuing: %@", [queueId.url description]); 

// [self.audioPlayer queueDataSource:[STKAudioPlayer dataSourceFromURL:queueId.url] withQueueItemId:[[SampleQueueId alloc] initWithUrl:queueId.url andCount:queueId.count+1]]; 
} 

Après cela, vous devez écrire arrêter les actions:

-(void) audioPlayer:(STKAudioPlayer*)audioPlayer didFinishPlayingQueueItemId:(NSObject*)queueItemId withReason:(STKAudioPlayerStopReason)stopReason andProgress:(double)progress andDuration:(double)duration 
{ 
    SampleQueueId* queueId = (SampleQueueId*)queueItemId; 
    NSLog(@"Finished: %@", [queueId.url description]); 


    if(stopReason == STKAudioPlayerStopReasonEof) 
     { 
      if(self.isMainAudioPlay) 
      { 
       [self.mainAudioPlayer setState:STKAudioPlayerStateStopped]; 
       [self.mainAudioPlayer stop]; 
       self.playMainAudioFrame.image = [UIImage imageNamed:PlayIconMain]; 
      } 
      else 
      { 
      [self.audioPlayer setState:STKAudioPlayerStateStopped]; 
      [self.audioPlayer stop]; 

      if(self.comments.count > 0) 
      { 
       UITableView *tableView = self.tabelView; 
       RCommentsModel *newsStop = (self.comments)[self.indexpathForStop.row]; 
       newsStop.commentPlayIcon = PlayIconMain; 
       [self.comments replaceObjectAtIndex:self.indexpathForStop.row withObject:newsStop]; 

       [tableView beginUpdates]; 
       [tableView reloadRowsAtIndexPaths:@[self.indexpathForStop] withRowAnimation:UITableViewRowAnimationNone]; 
       [tableView endUpdates]; 
      } 
      } 
     } 
     else if (stopReason == STKAudioPlayerStopReasonUserAction) 
     { 
      if(self.isMainAudioPlay) 
      { 
       [self.mainAudioPlayer setState:STKAudioPlayerStateStopped]; 
       [self.mainAudioPlayer stop]; 
       self.playMainAudioFrame.image = [UIImage imageNamed:PlayIconMain]; 
      } 
      else 
      { 
      [self.audioPlayer setState:STKAudioPlayerStateStopped]; 
      [self.audioPlayer stop]; 

      if(self.comments.count > 0) 
      { 
       UITableView *tableView = self.tabelView; 

       RCommentsModel *newsStop = (self.comments)[self.indexpathForStop.row]; 
       newsStop.commentPlayIcon = PlayIconMain; 
       [self.comments replaceObjectAtIndex:self.indexpathForStop.row withObject:newsStop]; 

       [tableView beginUpdates]; 
       [tableView reloadRowsAtIndexPaths:@[self.indexpathForStop] withRowAnimation:UITableViewRowAnimationNone]; 
       [tableView endUpdates]; 
      } 
      } 
     } 
     else if (stopReason == STKAudioPlayerStopReasonNone) 
     { 

     } 
} 

Hope it helps :) Je passe beaucoup de temps pour la réparer - et c'est travaillé!