Esempio n. 1
0
        /// <summary>
        /// Back button event raised.
        /// UWP WebView native back function doesn't respect history.pushState so this
        /// event is sent to the WebView as JS command using the InvokeScript method
        /// </summary>
        private async void NavigationBackRequested(object sender, BackRequestedEventArgs e)
        {
            if (!WebPlayer.CanGoBack)
            {
                return;
            }
            e.Handled = true;

            InvokedByBackEvent = true;
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                                      await WebPlayer.InvokeScriptAsync("eval", new [] { "history.back();" }));
        }
Esempio n. 2
0
        /// <summary>
        /// Receive control messages from the web player
        /// </summary>
        public async void ScriptNotify(object sender, NotifyEventArgs e)
        {
            var data = e.Value.Split('\n');

            switch (data[0])
            {
            // Custom styles are ready to be loaded
            case "LoadCustomStyles":
                await WebPlayer.InvokeScriptAsync("AppendCustomStyle", new[] { File.ReadAllText("WebPlayer/Style/Player.min.css") });

                break;

            // Song info change
            case "SystemMediaControlsSong":
                if (data.Length < 3)
                {
                    return;
                }
                SystemMediaControls.UpdateSongInfo(data[1], data[2]);
                break;

            // Media control buttons change
            case "SystemMediaControlsButtons":
                if (data.Length < 5)
                {
                    return;
                }
                SystemMediaControls.PrevButtonEnabled = data[1] == "true";
                SystemMediaControls.NextButtonEnabled = data[2] == "true";
                SystemMediaControls.PlayButtonEnabled = data[3] == "true";
                SystemMediaControls.IsPlaying         = data[4] == "true";
                break;

            // Transparent tile pin request
            case "RequestPinTransparentTile":
                TransparentTile.PinRequest();
                break;

            // Load default web player page
            case "RequestReloadWebPlayer":
                LoadWebPlayer();
                break;

            default:
                Debug.WriteLine($"Unknown web player message: {e.Value}");
                break;
            }
        }