0

I'm trying to add a List of Interviews to an AVQueuePlayer in Xamarin.iOS, and that is working for me. I do however need to be able to get some properties off the class I use to create the AVPlayerItems

My Interview Class:

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;
        }

I have a method in my PlayerClass that looks like this:

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

This will play my audio files (stored on SoundCloud) perfectly, but i need to update some labels with the Interview.Person.PersonName and Interview.Topic.TopicName. Is there any way I can get to access those properties after I've created the AVPlayerItem from the AudioID in the Interview? Only thing I've been able to find is MetaData, but my audio files do not contain any metadata.

4

1 回答 1

2

您不能将任意数据附加到排队的 AVPlayerItem 对象,因此一种解决方案是以其他方式将任意数据与 AVPlayerItem 对象相关联。例如,如果你从一个 AVURLAsset 开始生成你的 AVPlayerItem,那么 AVPlayerItem 有一个assetwhich(因为它是一个 AVURLAsset)有一个URL,所以现在我们可以想象一个 NSDictionary,其中键是 URL,值是对应的 Interview 对象.

于 2014-04-22T20:22:23.940 回答