Exemple #1
0
        private async Task RefreshQueueAsync(int[] itemIdsToFetch = null)
        {
            IMediaChannel mediaChannel = MediaSender.GetChannel <IMediaChannel>();

            int[] itemIds = itemIdsToFetch ?? await mediaChannel?.QueueGetItemIdsMessage();

            if (itemIds != null && itemIds.Count() > 0)
            {
                Queue <int>       itemIdsQueue = new Queue <int>(itemIds);
                IList <QueueItem> currentQueue = Queue.ToList();

                while (itemIdsQueue.Count > 0)
                {
                    foreach (QueueItem item in await mediaChannel.QueueGetItemsMessage(itemIdsQueue.DequeueChunk(20).ToArray()))
                    {
                        if (currentQueue.FirstOrDefault(i => i.ItemId == item.ItemId) != null)
                        {
                            currentQueue[currentQueue.IndexOf(Queue.FirstOrDefault(i => i.ItemId == item.ItemId))] = item;
                        }
                        else
                        if (item.OrderId < currentQueue.Count)
                        {
                            currentQueue.Insert((int)item.OrderId, item);
                        }
                        else
                        {
                            currentQueue.Add(item);
                        }
                    }
                }

                Queue = new ObservableCollection <QueueItem>(currentQueue);
            }
        }
Exemple #2
0
        public static async Task play(string url, string title, string subtitle, string image)
        {
            mediaChannel = sender.GetChannel <IMediaChannel>();
            await sender.LaunchAsync(mediaChannel);

            var mediaInfo = new MediaInformation()
            {
                ContentId = url
            };

            mediaInfo.Metadata = new GenericMediaMetadata();
            if (title != null)
            {
                mediaInfo.Metadata.Title = title;
            }
            if (subtitle != null)
            {
                mediaInfo.Metadata.Subtitle = subtitle;
            }
            if (image != null)
            {
                mediaInfo.Metadata.Images    = new GoogleCast.Models.Image[1];
                mediaInfo.Metadata.Images[0] = new GoogleCast.Models.Image()
                {
                    Url = image
                };
            }
            mediastatus = await mediaChannel.LoadAsync(mediaInfo);
        }
 public void ChromecastDisconnect(object sender, EventArgs e)
 {
     Debug.WriteLine("Disconnected from chromecast");
     mediaChannel = null;
     StopIfPlaying();
     StopWebserver();
     RevertSettings();
 }
Exemple #4
0
 public static async Task connectToChannel()
 {
     try
     {
         mediaChannel = sender.GetChannel <IMediaChannel>();
         mediastatus  = await mediaChannel.GetStatusAsync();
     }
     catch { }
 }
        public static void SetApplicationId(this IMediaChannel mediaChannel, string applicationId)
        {
            var field = mediaChannel.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic).FirstOrDefault(f => f.Name.StartsWith("<ApplicationId>"));

            if (field != null)
            {
                field.SetValue(mediaChannel, applicationId);
            }
        }
        protected void OnChromecastSelection(object sender, EventArgs e)
        {
            //If the webserver started with no issues
            try
            {
                //If there's already an active connection
                if (csSender != null)
                {
                    MessageBox.Show("There is already an active connection to a device. Please Disconnect then try again");
                    return;
                }
                //If the webserver started with an issue
                if (StartWebserver() == -1)
                {
                    return;
                }

                //Change some musicbee settings
                ChangeSettings();
            }
            catch (Exception ex)
            {
                MessageBox.Show("The webserver could not be started. Cancelling\n Error: " + ex.Message);
                return;
            }


            using (var cs = new ChromecastPanel(
                       Color.FromArgb(mbApiInterface.Setting_GetSkinElementColour(SkinElement.SkinInputPanel, ElementState.ElementStateDefault, ElementComponent.ComponentBackground))))
            {
                try
                {
                    cs.StartPosition = FormStartPosition.CenterParent;
                    cs.ShowDialog();

                    mediaChannel = cs.ChromecastMediaChannel;
                    csSender     = cs.ChromecastSender;
                    if (csSender == null)
                    {
                        RevertSettings();
                        return;
                    }

                    PauseIfPlaying();

                    //Maybe move this somewhere else?
                    csSender.GetChannel <IMediaChannel>().StatusChanged += Synchronize_Reciever;
                    csSender.Disconnected += ChromecastDisconnect;
                }
                catch (NullReferenceException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemple #7
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
            { }
        }
Exemple #8
0
        public async Task <bool> TryRefreshAsync()
        {
            try
            {
                await ConnectAsync();

                ISender       sender       = MediaSender;
                IMediaChannel mediaChannel = sender.GetChannel <IMediaChannel>();
                await mediaChannel.GetStatusAsync();
                await RefreshQueueAsync();

                return(true);
            }
            catch { }
            return(false);
        }
Exemple #9
0
        public async Task <bool> Connect(string byName)
        {
            IReceiver receiver = this.Get(byName);
            var       sender   = new Sender();

            this.logger.LogInformation("Connecting...");
            await sender.ConnectAsync(receiver);


            IMediaChannel mChannel = sender.GetChannel <IMediaChannel>();
            await sender.LaunchAsync(mChannel);

            this.mediaChannel = mChannel;
            this.Connected    = true;
            return(true);
        }
Exemple #10
0
        private async Task PlayVideo()
        {
            IReceiver selectedCastDevice = CvChromecastDevices.SelectedItem as IReceiver;

            if (selectedCastDevice == null)
            {
                return;
            }

            Sender ccSender = new Sender();
            await ccSender.ConnectAsync(selectedCastDevice);

            IMediaChannel mediaChannel = ccSender.GetChannel <IMediaChannel>();
            await ccSender.LaunchAsync(mediaChannel);

            MediaStatus mediaStatus = await mediaChannel.LoadAsync(new MediaInformation()
            {
                ContentId = EnUrl.Text
            });

            CvChromecastDevices.SelectedItem = null;
            await CloseReceiversList();
        }
Exemple #11
0
        public Player(
            ILogger logger,
            IReceiver receiver,
            string destinationId = AppConstants.DESTINATION_ID,
            string senderId      = AppConstants.SENDER_ID,
            bool logToConsole    = true,
            bool logTrace        = false)
        {
            _logger         = logger;
            _destinationId  = destinationId;
            CanLogToConsole = logToConsole;
            CanLogTrace     = logTrace;

            _sender = new Sender(_logger, senderId, receiver, HandleResponseMsg);
            _sender.Disconnected += OnDisconnect;
            _connectionChannel    = new ConnectionChannel(destinationId);
            _heartbeatChannel     = new HeartbeatChannel(destinationId);
            _mediaChannel         = new MediaChannel(destinationId, async() =>
            {
                var app = await _receiverChannel.GetApplication(_sender, _connectionChannel, _mediaChannel.Namespace);
                return(app.SessionId);
            });
            _receiverChannel = new ReceiverChannel(destinationId);
        }
Exemple #12
0
 private bool IsStopped(IMediaChannel mediaChannel)
 {
     return(mediaChannel.Status == null || !String.IsNullOrEmpty(mediaChannel.Status.FirstOrDefault()?.IdleReason));
 }