简体   繁体   English

使用AVQueuePlayer的属性

[英]Properties with AVQueuePlayer

I'm trying to add a List of Interviews to an AVQueuePlayer in Xamarin.iOS, and that is working for me. 我正在尝试在Xamarin.iOS中向AVQueuePlayer添加一个访谈列表,这对我有用。 I do however need to be able to get some properties off the class I use to create the AVPlayerItems 但是我需要能够从我用来创建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: 我的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 ();
            }
        }

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. 这将完美播放我的音频文件(存储在SoundCloud上),但我需要使用Interview.Person.PersonName和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? 在我从面试中的AudioID创建AVPlayerItem后,有什么办法可以访问这些属性吗? Only thing I've been able to find is MetaData, but my audio files do not contain any metadata. 我唯一能找到的是MetaData,但我的音频文件不包含任何元数据。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM