2014-04-22 41 views
0

我試圖添加到Xamarin.iOS中的AVQueuePlayer採訪列表,這對我來說。然而,我需要能夠得到一些性質關閉I類用於創建AVPlayerItems屬性與AVQueuePlayer

我的訪談類:

public class Interview 
    { 
     public int Id { get; set; } 
     public Topic Topic { get; set; } 
     public Person Person { get; set; } 
     public string VideoURL { get; set; } 
     public int AudioID { get; set; } 

     public Interview() 
     { 
     } 

     public Interview (int id, Topic t, Person p, string videoUrl, int audioId) 
     { 
      Id = id; 
      Topic = t; 
      Person = p; 
      VideoURL = videoUrl; 
      AudioID = audioId; 
     } 

我在PlayerClass的方法,看起來像這樣:

void AudioPlayWithAVQueuePlayer() 
     { 
      Console.WriteLine ("AVPlayer"); 
      var center = NSNotificationCenter.DefaultCenter; 
      //int pointer = 0; 
      List<AVPlayerItem> playeritems = new List<AVPlayerItem>(); 
      foreach (Interview i in appDelegate.currentlyPlaying.Interviews) { 
       AVAsset _asset; 
       AVPlayerItem _playerItem; 
       _asset = AVAsset.FromUrl (new NSUrl ("https://api.soundcloud.com/tracks/" + i.AudioID + "/stream?client_id=clientID&oauth_token=token")); 


       _playerItem = new AVPlayerItem (_asset); 

       playeritems.Add (_playerItem); 
      } 

      appDelegate.avPlayer = new AVQueuePlayer (playeritems.ToArray()); 
      appDelegate.avPlayer.Play(); 
      } 
     } 

這將播放我的音頻文件(存儲在SoundCloud上),但我需要使用Interview.Person.PersonName和Interview.Topic.TopicName更新一些標籤。在Interview中從AudioID創建AVPlayerItem後,有什麼方法可以訪問這些屬性? 我唯一能找到的是MetaData,但我的音頻文件不包含任何元數據。

回答

2

您不能將任意數據附加到排隊的AVPlayerItem對象,因此一種解決方案是將任意數據與某些其他方式中的AVPlayerItem對象相關聯。例如,如果你從一個AVURLAsset開始生成你的AVPlayerItem,那麼AVPlayerItem有一個asset(因爲它是一個AVURLAsset)有URL,所以現在我們可以想象一個NSDictionary,其中的鍵是URL和值是相對應的採訪對象。

+0

很酷。具有很大的意義,而且很容易做到。非常感謝。 – catu