public async Task QueueItem(string hashedName, string songFileExt, int duration, string artist, string title, string album)
 {
     QueueItem[] i = new QueueItem[]
     {
         new QueueItem
         {
             Media = new MediaInformation()
             {
                 ContentId  = HttpUtility.UrlPathEncode(mediaContentURL + hashedName + songFileExt),
                 StreamType = StreamType.Buffered,
                 Duration   = duration / 1000,
                 Metadata   = new MusicTrackMediaMetadata
                 {
                     Artist    = artist,
                     Title     = title,
                     AlbumName = album,
                     Images    = new[] {
                         new GoogleCast.Models.Image
                         {
                             Url = mediaContentURL + hashedName + ".jpg"
                         }
                     },
                 }
             },
             Autoplay = true,
         }
     };
     await mediaChannel.QueueInsertAsync(i);
 }
Exemplo n.º 2
0
        public async Task PlayAsync()
        {
            try
            {
                await SendChannelCommandAsync <IMediaChannel>(!IsInitialized || IsStopped,
                                                              async c =>
                {
                    if (insertingItems.Count > 0 && await ConnectAsync())
                    {
                        ISender sender             = MediaSender;
                        IMediaChannel mediaChannel = sender.GetChannel <IMediaChannel>();
                        await sender.LaunchAsync(mediaChannel);

                        Queue <QueueItem> itemsQueue = new Queue <QueueItem>(insertingItems);

                        await mediaChannel.QueueLoadAsync(RepeatMode.RepeatOff, itemsQueue.DequeueChunk(20).ToArray());

                        await RefreshQueueAsync();

                        while (itemsQueue.Count > 0)
                        {
                            await mediaChannel.QueueInsertAsync(itemsQueue.DequeueChunk(20).ToArray());
                        }

                        insertingItems.Clear();

                        IsInitialized = true;
                    }
                },
                                                              async c =>
                {
                    if (insertingItems.Count > 0)
                    {
                        Queue <QueueItem> itemsQueue = new Queue <QueueItem>(insertingItems);

                        while (itemsQueue.Count > 0)
                        {
                            await MediaSender.GetChannel <IMediaChannel>().QueueInsertAsync(itemsQueue.DequeueChunk(20).ToArray());
                        }

                        insertingItems.Clear();
                    }

                    await c.PlayAsync();
                });
            }
            catch
            { }
        }