2017-09-03 9 views
0

私はストアのIDを持つキューを設定し、play()の再生最初のトラックを呼び出すとき、私はキューのXインデックスを再生することができますどのように音楽プレーヤーに問題がありますか?インデックスを再生するMPMusicPlayerController setQueueWithStoreIDs?

var ids:[String] = [] 
    for song in self.queue 
    { 
     ids.append(String(song.epf_song_id)) 
    } 
    print("ids \(ids.count)") 
    applicationMusicPlayer.setQueueWithStoreIDs(ids) 
applicationMusicPlayer.play() 

答えて

0

私は解決策は、多分他の誰かが、私はMPMusicPlayerStoreQueueDescriptor

func playByStoreID(storeIds:[String]) 
{ 

    DispatchQueue.main.async { 
     //Prepare before play ios 10.1 and above 
     if #available(iOS 10.1, *) 
     { 

      var ids:[String] = [] 

      for i in self.queue 
      { 
       ids.append(String(i.epf_song_id)) 
      } 

      let descriptor:MPMusicPlayerStoreQueueDescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: ids) 
       descriptor.startItemID = storeIds[0] 

      self.applicationMusicPlayer.setQueue(with: descriptor) 
      self.applicationMusicPlayer.prepareToPlay { (error) in 

       //Wait 5 seconds 
       if (error != nil) 
       { 
        let errorCode:Int = (error! as NSError).code 

        print("[MUSIC PLAYER] Error \(String(describing: error))") 

        if errorCode == 4 && self.currectPlaying.failed == 0 
        { 
         print("[MUSIC PLAYER] Error Load track will play again after 5 seconds") 
         self.applicationMusicPlayer.stop() 
         self.currectPlaying.failed += 1 

         DispatchQueue.main.asyncAfter(deadline: .now() + 5 , execute: { 
          self.play_from_apple(false) 
         }) 

        }else 
        { 
         //Inform player to play with another streamer 
         self.fullFailure() 
         print("[MUSIC PLAYER] Error preparing : \(String(describing: error))") 
        } 

        return 
       }else 
       { 
        self.applicationMusicPlayer.play() 
        self.playedBy = .apple 
       } 
      } 

     }else 
     //Play directly ios below version 10.1 
     { 
      self.applicationMusicPlayer.setQueue(with: storeIds) 
      self.applicationMusicPlayer.play() 

     } 

    } 
} 
0

を使用する必要があります。これは、私が.. MPMusicPlayerController.systemMusicPlayer.prepareToPlayは、任意の値を返すことはなかった。この問題を修正する方法であるのに役立ちます発見しました。 .. 私はプレーヤーをプレイするためのトリックを作った後、この関数は値を返すようになった...エラーの場合はb/c私は別の画面に移動する必要があり、エラーがない場合はPlayerに移動する必要があります表示

  if #available(iOS 10.1, *) 
      { 
       let floatVersion = (UIDevice.current.systemVersion as NSString).floatValue 
       MPMusicPlayerController.systemMusicPlayer.setQueue(with: "YourSongID"); 
       if #available(iOS 11.1, *) 
       { 
        MPMusicPlayerController.systemMusicPlayer.play() 
       } 

       MPMusicPlayerController.systemMusicPlayer.prepareToPlay(completionHandler: { 
        (Eroror) in 
        if(Eroror == nil) 
        { 
         if(floatVersion < 11.1) 
         { 
          MPMusicPlayerController.systemMusicPlayer.pause() 
         } 

        } 
        else 
        { 

        } 
       }) 



      } 
+0

今後の読者に役立つように、コードを説明し、詳細を追加できますか? – LW001

関連する問題