Example #1
0
        private async void Companion_MessageReceived(CompanionClient sender, string Command, Dictionary<string, string> Parameters)
        {
            if (Parameters == null)
                LogMessage("Command Received: " + Command);
            else
            {
                string parameter = string.Empty;
                foreach (var v in Parameters)
                {
                    parameter += " " + v.Key + "=" + v.Value;
                }
                LogMessage("Command Received: " + Command + " Parameter: " + parameter);
            }
            switch (Command)
            {
                //https://testcertstorage.blob.core.windows.net/images/Radio.json
                //https://testcertstorage.blob.core.windows.net/images/Photos.json
                //https://testcertstorage.blob.core.windows.net/images/TVLive.json
                //https://testcertstorage.blob.core.windows.net/images/Video.json
                //https://testcertstorage.blob.core.windows.net/images/AudioVideoData.json

                case CompanionClient.commandOpenPlaylist:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
                    {
                        if ((Parameters != null) && (Parameters.ContainsKey(CompanionClient.parameterContent)))
                        {
                            string Path = Parameters[CompanionClient.parameterContent];
                            if (Path != null)
                            {
                                await LoadingData(Path);
                                MediaItem ms = comboStream.SelectedItem as MediaItem;
                                mediaUri.Text = ms.Content;
                                PlayCurrentUrl();
                                // Update control and play first video
                                UpdateControls();
                            }
                        }
                    });
                    break;
                case CompanionClient.commandOpen:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
                    {
                        if ((Parameters != null) && (Parameters.ContainsKey(CompanionClient.parameterContent)))
                        {
                            string path = Parameters[CompanionClient.parameterContent];
                            if (path != null)
                            {
                                string value = string.Empty;
                                Parameters.TryGetValue(CompanionClient.parameterPosterContent, out value);
                                string poster = value;
                                value = "0";
                                Parameters.TryGetValue(CompanionClient.parameterStart, out value);
                                long start = 0;
                                long.TryParse(value, out start);
                                Parameters.TryGetValue(CompanionClient.parameterDuration, out value);
                                long duration = 0;
                                long.TryParse(value, out duration);
                                await StartPlay(path, poster, start, duration);

                                // Update control and play first video
                                UpdateControls();
                            }
                        }
                    });
                    break;
                case CompanionClient.commandPlay:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        play_Click(null, null);
                    });
                    break;
                case CompanionClient.commandPause:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        pausePlay_Click(null, null);
                    });
                    break;
                case CompanionClient.commandPlayPause:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        playPause_Click(null, null);
                    });
                    break;
                case CompanionClient.commandSelect:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        int newIndex = -1;
                        if ((Parameters != null) &&
                            (Parameters.ContainsKey(CompanionClient.parameterIndex)))
                        {

                            if (int.TryParse(Parameters[CompanionClient.parameterIndex], out newIndex))
                                select_Click(null, null, newIndex);
                        }
                    });
                    break;
                case CompanionClient.commandPlus:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        plus_Click(null, null);
                    });
                    break;
                case CompanionClient.commandMinus:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        minus_Click(null, null);
                    });
                    break;
                case CompanionClient.commandFullWindow:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        fullwindow_Click(null, null);
                    });
                    break;
                case CompanionClient.commandFullScreen:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        fullscreen_Click(null, null);
                    });
                    break;
                case CompanionClient.commandWindow:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        if (mediaElement.IsFullWindow == true)
                            mediaElement.IsFullWindow = false;
                    });
                    break;
                case CompanionClient.commandMute:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        mute_Click(null, null);
                    });
                    break;
                case CompanionClient.commandVolumeUp:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        volumeUp_Click(null, null);
                    });
                    break;
                case CompanionClient.commandVolumeDown:
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        volumeDown_Click(null, null);
                    });
                    break;

                default:
                    LogMessage("Unknown Command");
                    break;
            }

        }
Example #2
0
        private void RegisterCompanion()
        {
            companion = new CompanionClient();
            companion.MessageReceived += Companion_MessageReceived;
            // Remote or Player
            Remote.Checked += Remote_Checked;
            Remote.Unchecked += Remote_Checked;

        }