Question

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.

Was it helpful?

Solution

You cannot attach arbitrary data to the queued AVPlayerItem objects, so one solution is to associate the arbitrary data with the AVPlayerItem objects in some other way. For example, if you start with an AVURLAsset to generate your AVPlayerItem, then the AVPlayerItem has an asset which (because it is an AVURLAsset) has a URL, so now we can imagine an NSDictionary where the keys are the URLs and the values are corresponding Interview objects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top