Example #1
0
        private void SendMessageToBackaudio(string key, object val)
        {
            ValueSet data = new ValueSet();

            data[key] = val;
            BackgroundMediaPlayer.SendMessageToBackground(data);
        }
Example #2
0
        public void SendMessage(string constants, object value)
        {
            var message = new ValueSet();

            message.Add(constants, value);
            BackgroundMediaPlayer.SendMessageToBackground(message);
        }
        public static void PauseCurrentSong()
        {
            ValueSet message = new ValueSet();

            message.Add(Constants.PauseTrack, null);
            BackgroundMediaPlayer.SendMessageToBackground(message);
        }
Example #4
0
        /// <summary>
        /// Called when IMediaPlayer [status changed].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="eventArgs">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void OnStatusChanged(object sender, EventArgs eventArgs)
        {
            if (this.mediaPlayer.Status == PlayerStatus.PLAYING)
            {
                //ThreadPool.RunOnUIThread(
                // async () =>
                // {
                if (BackgroundMediaPlayer.Current.CurrentState == MediaPlayerState.Paused)
                {
                    BackgroundMediaPlayer.Current.Play();
                }
                else
                {
                    //var file = this.trackMediaHelper.GetFileByMediaType(this.viewModel.CurrentTrack, TrackMediaType.AUDIO);

                    //this.mediaPlayer.Duration = file.Duration;
                    //this.viewModel.RaisePropertyChanged("Duration");

                    var fileUri = "";         //await this.trackMediaHelper.GetAuthenticatedUri(file);

                    BackgroundMediaPlayer.SendMessageToBackground(new ValueSet {
                        { "SetSource", fileUri.ToString() }
                    });
                }
                // });
            }
            else if (this.mediaPlayer.Status == PlayerStatus.PAUSED)
            {
                //ThreadPool.RunOnUIThread(
                //    async () =>
                //   {
                BackgroundMediaPlayer.Current.Pause();
                //   });
            }
        }
Example #5
0
        private void SendMessage(string constants)// SendMessage(constants,"")
        {
            var value = new ValueSet();

            value.Add(constants, "");
            BackgroundMediaPlayer.SendMessageToBackground(value);
        }
Example #6
0
 /// <summary>
 /// Отправляет сообщение фоновому процессу проигрывателя.
 /// </summary>
 /// <param name="message">Сообщение для отправки.</param>
 private void SendMessageToBackground(ValueSet message)
 {
     if (IsTaskRunning)
     {
         BackgroundMediaPlayer.SendMessageToBackground(message);
     }
 }
 private void Userimage_OnClick(object sender, RoutedEventArgs e)
 {
     if (userimage.IsChecked == true)
     {
         var vs = new ValueSet();
         vs.Add("state", "pause");
         try
         {
             BackgroundMediaPlayer.SendMessageToBackground(vs);
         }
         catch (Exception)
         {
             // ignored
         }
     }
     else if (userimage.IsChecked == false)
     {
         var vs = new ValueSet();
         vs.Add("state", "play");
         try
         {
             BackgroundMediaPlayer.SendMessageToBackground(vs);
         }
         catch (Exception)
         {
             // ignored
         }
     }
 }
 private void AppBarButtonPlay_Click(object sender, RoutedEventArgs e)
 {
     if (AudioPlay.IsMyBackgroundTaskRunning)
     {
         if (MediaPlayerState.Playing == BackgroundMediaPlayer.Current.CurrentState)
         {
             //正在播放,播放暂停
             BackgroundMediaPlayer.Current.Pause();
             //控件状态 显示播放
             SetPlayButtonState(false);
         }
         else if (MediaPlayerState.Paused == BackgroundMediaPlayer.Current.CurrentState)
         {
             BackgroundMediaPlayer.Current.Play();
             //控件状态 显示暂停
             SetPlayButtonState(true);
         }
         else if (MediaPlayerState.Closed == BackgroundMediaPlayer.Current.CurrentState)
         {
             var message = new ValueSet();
             message.Add("playsinglefile", "ms-appx:///Assets/VideoSample/Media/红豆.mp3");
             BackgroundMediaPlayer.SendMessageToBackground(message);
             //控件状态 显示暂停
             SetPlayButtonState(true);
         }
     }
     else
     {
         MyToast.ShowToast("提示", "暂无音乐播放,请先选一首歌曲");
     }
 }
Example #9
0
 private async void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         BackgroundMediaPlayer.SendMessageToBackground(new ValueSet());
     });
 }
Example #10
0
        /// <summary>
        /// Обновить состояние случайного режима.
        /// </summary>
        public void UpdateShuffleMode()
        {
            var valueSet = new ValueSet();

            valueSet.Add(PlayerConstants.UPDATE_SHUFFLE_MODE, null);
            BackgroundMediaPlayer.SendMessageToBackground(valueSet);
        }
Example #11
0
        /// <summary>
        /// Обновить состояние режима повтора.
        /// </summary>
        public void UpdateRepeatMode()
        {
            var valueSet = new ValueSet();

            valueSet.Add(PlayerConstants.UPDATE_REPEAT_MODE, null);
            BackgroundMediaPlayer.SendMessageToBackground(valueSet);
        }
Example #12
0
        /// <summary>
        /// Tells the background audio agent to skip to the next track.
        /// </summary>
        public void Next()
        {
            var value = new ValueSet();

            value.Add(Constants.conSkipNext, "");
            BackgroundMediaPlayer.SendMessageToBackground(value);
        }
Example #13
0
        /// <summary>
        /// Sends message to the background task to skip to the previous track.
        /// </summary>
        public void Prevent()
        {
            var value = new ValueSet();

            value.Add(Constants.conSkipPrevious, "");
            BackgroundMediaPlayer.SendMessageToBackground(value);
        }
Example #14
0
 /// <summary>
 /// Initialize Background Media Player Handlers and starts playback
 /// </summary>
 private void StartBackgroundAudioTask()
 {
     if (!this.isFirstRunTask)
     {
         var backgroundtaskinitializationresult = this.page.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
         {
             bool result = SererInitialized.WaitOne(2000);
             //Send message to initiate playback
             if (result == true)
             {
                 var message = new ValueSet();
                 message.Add(Constants.conStartPlayback, "0");
                 BackgroundMediaPlayer.SendMessageToBackground(message);
             }
             else
             {
                 Debug.WriteLine("Background Audio Task didn't start in expected time");
             }
         }
                                                                                );
         backgroundtaskinitializationresult.Completed = new AsyncActionCompletedHandler(BackgroundTaskInitializationCompleted);
     }
     else
     {
         var message = new ValueSet();
         message.Add(Constants.conStartPlayback, "0");
         BackgroundMediaPlayer.SendMessageToBackground(message);
     }
 }
        private static void QueryForBackgroundTask()
        {
            ValueSet message = new ValueSet();

            message.Add(Constants.BackgroundTaskQuery, null);
            BackgroundMediaPlayer.SendMessageToBackground(message);
        }
        private async void NetworkInformation_NetworkStatusChanged(object sender)
        {
            await Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                async() =>
            {
                if (Helpers.HasInternet())
                {
                    userimage.IsChecked = false;
                    if (!(Application.Current as App).PVM.ProducersLoaded)
                    {
                        await(Application.Current as App).PVM.LoadProducers();
                    }
                    (Application.Current as App).PVM.Callback(null);
                    var vs = new ValueSet();
                    vs.Add("state", "play");
                    BackgroundMediaPlayer.SendMessageToBackground(vs);
                }
                else
                {
                    userimage.IsChecked = true;
                    var vs = new ValueSet();
                    vs.Add("state", "pause");
                    BackgroundMediaPlayer.SendMessageToBackground(vs);

                    (Application.Current as App).PVM.NowPlaying = new Producer
                    {
                        Name = "No Internet Connection.",
                        Time = ""
                    };
                }
            });
        }
Example #17
0
        private void StartBackgroundAudioTask()
        {
            AddMediaPlayerEventHandlers();
            bool         success        = false;
            IAsyncAction taskInitResult = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                success = taskInitialized.WaitOne(2000);
                if (success)
                {
                    ValueSet message = new ValueSet();
                    message.Add(SharedStrings.BACKGROUND_AUDIO_START_PLAYBACK, "0");
                    BackgroundMediaPlayer.SendMessageToBackground(message);
                    status.Log(LocalizableStrings.BACKGROUND_AUDIO_TASK_INVOKED);
                }
                else
                {
                    status.Log(SharedStrings.BACKGROUND_AUDIO_STARTUP_TIMEOUT);
                }
            });

            if (success)
            {
                taskInitResult.Completed = new AsyncActionCompletedHandler(taskInitResult_Completed);
            }
        }
        public static void StopPlayback()
        {
            ValueSet message = new ValueSet();

            message.Add(Constants.StopPlayback, null);
            BackgroundMediaPlayer.SendMessageToBackground(message);
        }
Example #19
0
    public void SendMessageToBackground(String x, String y)
    {
        ValueSet valueSet = new ValueSet();

        valueSet.Add(x, y);
        BackgroundMediaPlayer.SendMessageToBackground(valueSet);
    }
Example #20
0
        private void SendMessageToBackground(PlayQueueConstantFGMessageId messageId, object value)
        {
            var message = new ValueSet();

            message.Add(PlayQueueMessageHelper.FGMessageIdToMessageString(messageId), value);
            BackgroundMediaPlayer.SendMessageToBackground(message);
        }
        async private void LandingPage_Loaded(object sender, RoutedEventArgs e)
        {
            _timer.Start();
            img_banner.SetImage(_images[_image_index]);
            _image_index++;

            //initialize the background audio task
            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                BackgroundMediaPlayer.SendMessageToBackground(new ValueSet());
            });

            //set the starting point of the map
            map.Center = new Geopoint(new BasicGeoposition
            {
                Latitude  = App.State.NextEvent.Latitude.Value,
                Longitude = App.State.NextEvent.Longitude.Value,
            });
            map.ZoomLevel = 17.5;
            //MapIcon map_icon = new MapIcon();
            //map_icon.Title = App.State.NextEvent.EventTitle;
            //map_icon.Location = map.Center;
            //map.MapElements.Add(map_icon);

            SymbolIcon symbol = new SymbolIcon(Symbol.Favorite);

            map.Children.Add(symbol);
            MapControl.SetLocation(symbol, map.Center);


            //
            //clear the backstack so that you cannot navigate back from
            //this page
            Frame.BackStack.Clear();
        }
Example #22
0
        /// <summary>
        /// Sends message to background informing app has resumed
        /// Subscribe to MediaPlayer events
        /// </summary>
        void ForegroundApp_Resuming(object sender, object e)
        {
            ApplicationSettingsHelper.SaveSettingsValue(Constants.AppState, Constants.ForegroundAppActive);

            // Verify if the task was running before
            if (IsMyBackgroundTaskRunning)
            {
                //if yes, reconnect to media play handlers
                AddMediaPlayerEventHandlers();

                //send message to background task that app is resumed, so it can start sending notifications
                ValueSet messageDictionary = new ValueSet();
                messageDictionary.Add(Constants.AppResumed, DateTime.Now.ToString());
                BackgroundMediaPlayer.SendMessageToBackground(messageDictionary);

                if (BackgroundMediaPlayer.Current.CurrentState == MediaPlayerState.Playing)
                {
                    playButton.Content = "| |";     // Change to pause button
                }
                else
                {
                    playButton.Content = ">";     // Change to play button
                }
                txtCurrentTrack.Text = CurrentTrack;
            }
            else
            {
                playButton.Content   = ">";   // Change to play button
                txtCurrentTrack.Text = "";
            }
        }
Example #23
0
        private async void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
        {
            ToggleSwitch toggleSwitch = sender as ToggleSwitch;

            if (toggleSwitch != null)
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    if (toggleSwitch.IsOn)
                    {
                        if (BackgroundMediaPlayer.Current.CurrentState != MediaPlayerState.Playing)
                        {
                            var message = new ValueSet
                            {
                                {
                                    "Play",
                                    urlRadio
                                }
                            };
                            BackgroundMediaPlayer.SendMessageToBackground(message);
                        }
                    }
                    else
                    {
                        BackgroundMediaPlayer.Current.Pause();
                    }
                });
            }
        }
Example #24
0
        private static void SendMessageToBackground(string name, object parameter)
        {
            var valueSet = new ValueSet();

            valueSet.Add(name, parameter);
            BackgroundMediaPlayer.SendMessageToBackground(valueSet);
        }
Example #25
0
        public async void PlaySong(QueueSong song)
        {
            if (song == null || song.Song == null)
            {
                CurtainPrompt.ShowError("Song seems to be empty...");
                return;
            }

            Insights.Track(
                "Play Song",
                new Dictionary <string, string>
            {
                { "Name", song.Song.Name },
                { "ArtistName", song.Song.ArtistName },
                { "ProviderId", song.Song.ProviderId }
            });

            if (_isShutdown)
            {
                await AddMediaPlayerEventHandlers();
            }

            _appSettings.Write("RadioId", null);
            _appSettings.Write("RadioMode", false);
            _appSettings.Write(PlayerConstants.CurrentTrack, song.Id);

            var message = new ValueSet {
                { PlayerConstants.StartPlayback, null }
            };

            BackgroundMediaPlayer.SendMessageToBackground(message);

            RaiseEvent(TrackChanged);
        }
Example #26
0
        public void NextSong()
        {
            var value = new ValueSet {
                { PlayerConstants.SkipNext, "" }
            };

            BackgroundMediaPlayer.SendMessageToBackground(value);
        }
Example #27
0
        public void PrevSong()
        {
            var value = new ValueSet {
                { PlayerConstants.SkipPrevious, "" }
            };

            BackgroundMediaPlayer.SendMessageToBackground(value);
        }
Example #28
0
        public static void SendMessageToBackground <T>(T message)
        {
            var payload = new ValueSet();

            payload.Add(MessageService.MessageType, typeof(T).FullName);
            payload.Add(MessageService.MessageBody, JsonHelper.ToJson(message));
            BackgroundMediaPlayer.SendMessageToBackground(payload);
        }
 private void _media_control_ButtonPressed(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs args)
 {
     //send the a message to the background to handle the action
     BackgroundMediaPlayer.SendMessageToBackground(new ValueSet
     {
         { "action", args.Button.ToString() }
     });
 }
Example #30
0
        public void RestorePlaylist()
        {
#if WINDOWS_PHONE_APP
            var msgDictionanary = new ValueSet();
            msgDictionanary.Add(BackgroundAudioConstants.RestorePlaylist, "");
            BackgroundMediaPlayer.SendMessageToBackground(msgDictionanary);
#endif
        }