コード例 #1
0
        /// <summary>
        /// Fires when a message is recieved from the foreground app
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BackgroundMediaPlayer_MessageReceivedFromForeground(object sender, MediaPlayerDataReceivedEventArgs e)
        {
            foreach (string key in e.Data.Keys)
            {
                switch (key.ToLower())
                {
                case Constants.AppSuspended:
                    Debug.WriteLine("App suspending");     // App is suspended, you can save your task state at this point
                    foregroundAppState = ForegroundAppStatus.Suspended;
                    ApplicationSettingsHelper.SaveSettingsValue(Constants.CurrentTrack, Playlist.CurrentTrackName);
                    ApplicationSettingsHelper.SaveSettingsValue(Constants.BackgroundTaskState, Constants.BackgroundTaskRunning);
                    break;

                case Constants.AppResumed:
                    Debug.WriteLine("App resuming");     // App is resumed, now subscribe to message channel
                    foregroundAppState = ForegroundAppStatus.Active;
                    break;

                case Constants.StartPlayback:     //Foreground App process has signalled that it is ready for playback
                    Debug.WriteLine("Starting Playback");
                    StartPlayback();
                    break;

                case Constants.SkipNext:     // User has chosen to skip track from app context.
                    Debug.WriteLine("Skipping to next");
                    SkipToNext();
                    break;

                case Constants.SkipPrevious:     // User has chosen to skip track from app context.
                    Debug.WriteLine("Skipping to previous");
                    SkipToPrevious();
                    break;
                }
            }
        }
コード例 #2
0
        private void BackgroundMediaPlayer_MessageReceivedFromForeground(object sender, MediaPlayerDataReceivedEventArgs e)
        {
            foreach (string key in e.Data.Keys)
            {
                switch (key.ToLower())
                {
                case SharedStrings.BACKGROUND_AUDIO_APP_SUSPENDED:
                    foregroundAppState = ForegroundAppStatus.Suspended;
                    ApplicationSettingsHelper.SaveSettingsValue(SharedStrings.BACKGROUND_AUDIO_CURRENT_TRACK, Playlist.CurrentTrackName);
                    break;

                case SharedStrings.BACKGROUND_AUDIO_APP_RESUMED:
                    foregroundAppState = ForegroundAppStatus.Active;
                    break;

                case SharedStrings.BACKGROUND_AUDIO_START_PLAYBACK:
                    StartPlayback();
                    break;

                case SharedStrings.BACKGROUND_AUDIO_SKIP_NEXT:
                    SkipToNext();
                    break;

                case SharedStrings.BACKGROUND_AUDIO_SKIP_PREVIOUS:
                    SkipToPrevious();
                    break;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// The Run method is the entry point of a background task.
        /// </summary>
        /// <param name="taskInstance"></param>
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            Debug.WriteLine("Background Audio Task " + taskInstance.Task.Name + " starting...");
            // Initialize SMTC object to talk with UVC.
            //Note that, this is intended to run after app is paused and
            //hence all the logic must be written to run in background process
            systemmediatransportcontrol = SystemMediaTransportControls.GetForCurrentView();
            systemmediatransportcontrol.ButtonPressed    += systemmediatransportcontrol_ButtonPressed;
            systemmediatransportcontrol.PropertyChanged  += systemmediatransportcontrol_PropertyChanged;
            systemmediatransportcontrol.IsEnabled         = true;
            systemmediatransportcontrol.IsPauseEnabled    = true;
            systemmediatransportcontrol.IsPlayEnabled     = true;
            systemmediatransportcontrol.IsNextEnabled     = true;
            systemmediatransportcontrol.IsPreviousEnabled = true;

            // Associate a cancellation and completed handlers with the background task.
            taskInstance.Canceled       += new BackgroundTaskCanceledEventHandler(OnCanceled);
            taskInstance.Task.Completed += Taskcompleted;

            var value = ApplicationSettingsHelper.ReadResetSettingsValue(Constants.AppState);

            if (value == null)
            {
                foregroundAppState = ForegroundAppStatus.Unknown;
            }
            else
            {
                foregroundAppState = (ForegroundAppStatus)Enum.Parse(typeof(ForegroundAppStatus), value.ToString());
            }

            //Add handlers for MediaPlayer
            BackgroundMediaPlayer.Current.CurrentStateChanged += Current_CurrentStateChanged;

            deferral = taskInstance.GetDeferral();
        }
コード例 #4
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            InitializeAndSetMediaTransportControl();

            taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);
            taskInstance.Task.Completed += Taskcompleted;

            var value = ApplicationSettingsHelper.ReadResetSettingsValue(ConstantValues.AppState);

            if (value == null)
                _foregroundAppState = ForegroundAppStatus.Unknown;
            else
                _foregroundAppState = (ForegroundAppStatus)Enum.Parse(typeof(ForegroundAppStatus), value.ToString());

            BackgroundMediaPlayer.Current.CurrentStateChanged += Current_CurrentStateChanged;

            UpdateQueue();

            _queue.TrackChanged += playList_TrackChanged;

            BackgroundMediaPlayer.MessageReceivedFromForeground += BackgroundMediaPlayer_MessageReceivedFromForeground;

            if (_foregroundAppState != ForegroundAppStatus.Suspended)
            {
                ValueSet message = new ValueSet { { ConstantValues.BackgroundTaskStarted, "" } };
                BackgroundMediaPlayer.SendMessageToForeground(message);
            }

            _backgroundTaskStarted.Set();
            _backgroundtaskrunning = true;
            
            ApplicationSettingsHelper.SaveSettingsValue(ConstantValues.BackgroundTaskState, ConstantValues.BackgroundTaskRunning);
            _deferral = taskInstance.GetDeferral();
        }
コード例 #5
0
        /// <summary>
        /// The Run method is the entry point of a background task. 
        /// </summary>
        /// <param name="taskInstance"></param>
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            Debug.WriteLine("Background Audio Task " + taskInstance.Task.Name + " starting...");
            // Initialize SMTC object to talk with UVC.
            //Note that, this is intended to run after app is paused and
            //hence all the logic must be written to run in background process
            systemmediatransportcontrol = SystemMediaTransportControls.GetForCurrentView();
            systemmediatransportcontrol.ButtonPressed += systemmediatransportcontrol_ButtonPressed;
            systemmediatransportcontrol.PropertyChanged += systemmediatransportcontrol_PropertyChanged;
            systemmediatransportcontrol.IsEnabled = true;
            systemmediatransportcontrol.IsPauseEnabled = true;
            systemmediatransportcontrol.IsPlayEnabled = true;
            systemmediatransportcontrol.IsNextEnabled = true;
            systemmediatransportcontrol.IsPreviousEnabled = true;

            // Associate a cancellation and completed handlers with the background task.
            taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);
            taskInstance.Task.Completed += Taskcompleted;

            var value = ApplicationSettingsHelper.ReadResetSettingsValue(Constants.AppState);
            if (value == null)
                foregroundAppState = ForegroundAppStatus.Unknown;
            else
                foregroundAppState = (ForegroundAppStatus)Enum.Parse(typeof(ForegroundAppStatus), value.ToString());

            //Add handlers for MediaPlayer
            BackgroundMediaPlayer.Current.CurrentStateChanged += Current_CurrentStateChanged;

            deferral = taskInstance.GetDeferral();
        }
コード例 #6
0
ファイル: BackgroundPlayer.cs プロジェクト: robUx4/vlc-winrt
        /// <summary>
        /// The Run method is the entry point of a background task. 
        /// </summary>
        /// <param name="taskInstance"></param>
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            try
            {
                Debug.WriteLine("Background Audio Task " + taskInstance.Task.Name + " starting...");
                // Initialize SMTC object to talk with UVC. 
                //Note that, this is intended to run after app is paused and 
                //hence all the logic must be written to run in background process
                systemmediatransportcontrol = SystemMediaTransportControls.GetForCurrentView();
                systemmediatransportcontrol.ButtonPressed += systemmediatransportcontrol_ButtonPressed;
                systemmediatransportcontrol.PropertyChanged += systemmediatransportcontrol_PropertyChanged;
                systemmediatransportcontrol.IsEnabled = true;
                systemmediatransportcontrol.IsPauseEnabled = true;
                systemmediatransportcontrol.IsPlayEnabled = true;
                systemmediatransportcontrol.IsNextEnabled = true;
                systemmediatransportcontrol.IsPreviousEnabled = true;

                // Associate a cancellation and completed handlers with the background task.
                taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);
                taskInstance.Task.Completed += Taskcompleted;

                var value = ApplicationSettingsHelper.ReadResetSettingsValue(BackgroundAudioConstants.AppState);
                if (value == null)
                    foregroundAppState = ForegroundAppStatus.Unknown;
                else
                    foregroundAppState = (ForegroundAppStatus)Enum.Parse(typeof(ForegroundAppStatus), value.ToString());

                //Add handlers for MediaPlayer
                BackgroundMediaPlayer.Current.CurrentStateChanged += Current_CurrentStateChanged;

                //Add handlers for playlist trackchanged
                Playlist.TrackChanged += playList_TrackChanged;

                //Initialize message channel 
                BackgroundMediaPlayer.MessageReceivedFromForeground += BackgroundMediaPlayer_MessageReceivedFromForeground;

                //Send information to foreground that background task has been started if app is active
                if (foregroundAppState != ForegroundAppStatus.Suspended)
                {
                    ValueSet message = new ValueSet();
                    message.Add(BackgroundAudioConstants.BackgroundTaskStarted, "");
                    BackgroundMediaPlayer.SendMessageToForeground(message);
                }
                BackgroundTaskStarted.Set();
                backgroundtaskrunning = true;

                Playlist.PopulatePlaylist();
                var currentTrackIndex = ApplicationSettingsHelper.ReadSettingsValue(BackgroundAudioConstants.CurrentTrack);
                if (currentTrackIndex != null)
                {
                    Playlist.CurrentTrack = (int)currentTrackIndex;
                }
                ApplicationSettingsHelper.SaveSettingsValue(BackgroundAudioConstants.BackgroundTaskState, BackgroundAudioConstants.BackgroundTaskRunning);
                deferral = taskInstance.GetDeferral();
            }
            catch
            {
            }
        }
コード例 #7
0
        /// <summary>
        /// The Run method is the entry point of a background task.
        /// </summary>
        /// <param name="taskInstance"></param>
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            Debug.WriteLine("Background Audio Task " + taskInstance.Task.Name + " starting...");

            //SystemMediaTransportControls,是按下音量键后顶部弹出的控制音乐播放的控件。
            //设置 SystemMediaTransportControls 的各个按键属性以及事件的订阅
            systemmediatransportcontrol = SystemMediaTransportControls.GetForCurrentView();
            systemmediatransportcontrol.ButtonPressed    += systemmediatransportcontrol_ButtonPressed;
            systemmediatransportcontrol.PropertyChanged  += systemmediatransportcontrol_PropertyChanged;
            systemmediatransportcontrol.IsEnabled         = true;
            systemmediatransportcontrol.IsPauseEnabled    = true;
            systemmediatransportcontrol.IsPlayEnabled     = true;
            systemmediatransportcontrol.IsNextEnabled     = true;
            systemmediatransportcontrol.IsPreviousEnabled = true;

            // 关联取消 后台任务处理完成
            taskInstance.Canceled       += new BackgroundTaskCanceledEventHandler(OnCanceled);
            taskInstance.Task.Completed += Taskcompleted;

            //读取应用程序状态
            var value = ApplicationSettingsHelper.ReadResetSettingsValue(Constants.AppState);

            if (value == null)
            {
                foregroundAppState = ForegroundAppStatus.Unknown;
            }
            else
            {
                foregroundAppState = (ForegroundAppStatus)Enum.Parse(typeof(ForegroundAppStatus), value.ToString());
            }

            //添加在媒体播放器状态发生更改时处理函数
            BackgroundMediaPlayer.Current.CurrentStateChanged += Current_CurrentStateChanged;

            //Add handlers for playlist trackchanged
            //添加 后台播放列表变更时处理函数
            Playlist.TrackChanged  += playList_TrackChanged;
            Playlist.TrackComplete += playList_TrackComplete;

            //初始化消息通道 前台发往后台的信息
            BackgroundMediaPlayer.MessageReceivedFromForeground += BackgroundMediaPlayer_MessageReceivedFromForeground;

            //Send information to foreground that background task has been started if app is active
            //将信息发送到前景中的后台任务已经启动,如果应用程序被激活
            if (foregroundAppState != ForegroundAppStatus.Suspended)
            {
                ValueSet message = new ValueSet();
                message.Add(Constants.BackgroundTaskStarted, "");
                BackgroundMediaPlayer.SendMessageToForeground(message);
            }
            BackgroundTaskStarted.Set();
            backgroundtaskrunning = true;

            ApplicationSettingsHelper.SaveSettingsValue(Constants.BackgroundTaskState, Constants.BackgroundTaskRunning);
            object value11 = ApplicationSettingsHelper.ReadResetSettingsValue(Constants.BackgroundTaskState);

            deferral = taskInstance.GetDeferral();
        }
コード例 #8
0
        /// <summary>
        /// The Run method is the entry point of a background task.
        /// </summary>
        /// <param name="taskInstance"></param>
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            Debug.WriteLine("Background Audio Task " + taskInstance.Task.Name + " starting...");
            // Initialize SMTC object to talk with UVC.
            //Note that, this is intended to run after app is paused and
            //hence all the logic must be written to run in background process
            systemmediatransportcontrol = SystemMediaTransportControls.GetForCurrentView();
            systemmediatransportcontrol.ButtonPressed       += systemmediatransportcontrol_ButtonPressed;
            systemmediatransportcontrol.PropertyChanged     += systemmediatransportcontrol_PropertyChanged;
            systemmediatransportcontrol.IsEnabled            = true;
            systemmediatransportcontrol.IsPauseEnabled       = true;
            systemmediatransportcontrol.IsPlayEnabled        = true;
            systemmediatransportcontrol.IsNextEnabled        = false;
            systemmediatransportcontrol.IsPreviousEnabled    = false;
            systemmediatransportcontrol.IsFastForwardEnabled = false;

            // Associate a cancellation and completed handlers with the background task.
            taskInstance.Canceled       += new BackgroundTaskCanceledEventHandler(OnCanceled);
            taskInstance.Task.Completed += Taskcompleted;

            var value = ApplicationSettingsHelper.ReadResetSettingsValue(Constants.AppState);

            if (value == null)
            {
                foregroundAppState = ForegroundAppStatus.Unknown;
            }
            else
            {
                foregroundAppState = (ForegroundAppStatus)Enum.Parse(typeof(ForegroundAppStatus), value.ToString());
            }

            //Add handlers for MediaPlayer
            BackgroundMediaPlayer.Current.CurrentStateChanged += Current_CurrentStateChanged;

            //Add handlers for playlist trackchanged
            Playlist.TrackChanged += playList_TrackChanged;

            //Initialize message channel
            BackgroundMediaPlayer.MessageReceivedFromForeground += BackgroundMediaPlayer_MessageReceivedFromForeground;

            //Send information to foreground that background task has been started if app is active
            if (foregroundAppState != ForegroundAppStatus.Suspended)
            {
                ValueSet message = new ValueSet();
                message.Add(Constants.BackgroundTaskStarted, "BC Started");
                BackgroundMediaPlayer.SendMessageToForeground(message);
            }
            BackgroundTaskStarted.Set();
            backgroundtaskrunning = true;

            ApplicationSettingsHelper.SaveSettingsValue(Constants.BackgroundTaskState, Constants.BackgroundTaskRunning);
            deferral = taskInstance.GetDeferral();
        }
コード例 #9
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            transportControl = BackgroundMediaPlayer.Current.SystemMediaTransportControls;
            if (transportControl != null)
            {
                transportControl.ButtonPressed    += transportControl_ButtonPressed;
                transportControl.PropertyChanged  += transportControl_PropertyChanged;
                transportControl.IsEnabled         = true;
                transportControl.IsPauseEnabled    = true;
                transportControl.IsPlayEnabled     = true;
                transportControl.IsNextEnabled     = true;
                transportControl.IsPreviousEnabled = true;
            }

            taskInstance.Canceled       += new BackgroundTaskCanceledEventHandler(OnCanceled);
            taskInstance.Task.Completed += Taskcompleted;

            var value = ApplicationSettingsHelper.ReadResetSettingsValue(SharedStrings.BACKGROUND_AUDIO_APP_STATE);

            if (value == null)
            {
                foregroundAppState = ForegroundAppStatus.Unknown;
            }
            else
            {
                foregroundAppState = (ForegroundAppStatus)Enum.Parse(typeof(ForegroundAppStatus), value.ToString());
            }

            BackgroundMediaPlayer.Current.CurrentStateChanged += Current_CurrentStateChanged;
            Playlist.TrackChanged += playList_TrackChanged;
            BackgroundMediaPlayer.MessageReceivedFromForeground += BackgroundMediaPlayer_MessageReceivedFromForeground;

            //Send information to foreground that background task has been started if app is active
            if (foregroundAppState != ForegroundAppStatus.Suspended)
            {
                ValueSet message = new ValueSet();
                message.Add(SharedStrings.BACKGROUND_AUDIO_STARTED, "");
                BackgroundMediaPlayer.SendMessageToForeground(message);
            }
            backgroundTaskStarted.Set();
            backgroundTaskRunning = true;

            ApplicationSettingsHelper.SaveSettingsValue(SharedStrings.BACKGROUND_AUDIO_STATE, SharedStrings.BACKGROUND_AUDIO_RUNNING);
            deferral = taskInstance.GetDeferral();
        }
コード例 #10
0
        /// <summary>
        /// Fires when a message is recieved from the foreground app
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BackgroundMediaPlayer_MessageReceivedFromForeground(object sender, MediaPlayerDataReceivedEventArgs e)
        {
            foreach (string key in e.Data.Keys)
            {
                switch (key.ToLower())
                {
                case Constants.AppSuspended:
                    Debug.WriteLine("App suspending");     // App is suspended, you can save your task state at this point
                    foregroundAppState = ForegroundAppStatus.Suspended;
                    break;

                case Constants.AppResumed:
                    Debug.WriteLine("App resuming");     // App is resumed, now subscribe to message channel
                    foregroundAppState = ForegroundAppStatus.Active;
                    break;

                case Constants.StartPlayback:     //Foreground App process has signalled that it is ready for playback
                    Debug.WriteLine("Starting Playback");
                    StartPlayback();
                    break;
                }
            }
        }
コード例 #11
0
ファイル: BackgroundPlayer.cs プロジェクト: robUx4/vlc-winrt
        /// <summary>
        /// Fires when a message is recieved from the foreground app
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BackgroundMediaPlayer_MessageReceivedFromForeground(object sender, MediaPlayerDataReceivedEventArgs e)
        {
            foreach (string key in e.Data.Keys)
            {
                switch (key.ToLower())
                {
                    case BackgroundAudioConstants.PingBackground:
                        Debug.WriteLine("Received Ping from foreground"); // App is suspended, you can save your task state at this point
                        ValueSet message = new ValueSet();
                        message.Add(BackgroundAudioConstants.PingBackground, DateTime.Now.ToString());
                        BackgroundMediaPlayer.SendMessageToForeground(message);
                        break;
                    case BackgroundAudioConstants.AppSuspended:
                        Debug.WriteLine("App suspending"); // App is suspended, you can save your task state at this point
                        foregroundAppState = ForegroundAppStatus.Suspended;
                        ApplicationSettingsHelper.SaveSettingsValue(BackgroundAudioConstants.CurrentTrack, Playlist.CurrentTrackIndex);
                        break;
                    case BackgroundAudioConstants.AppResumed:
                        Debug.WriteLine("App resuming"); // App is resumed, now subscribe to message channel
                        foregroundAppState = ForegroundAppStatus.Active;
                        break;
                    case BackgroundAudioConstants.StartPlayback: //Foreground App process has signalled that it is ready for playback
                        Debug.WriteLine("Starting Playback");
                        StartPlayback();
                        break;

                    case BackgroundAudioConstants.UpdatePlaylist:
                        Debug.WriteLine("Updating playlist...");
                        Playlist.UpdatePlaylist();
                        break;
                    case BackgroundAudioConstants.ResetPlaylist:
                        var arg = new object();
                        if (e.Data.TryGetValue(BackgroundAudioConstants.ResetPlaylist, out arg))
                        {
                            Playlist.ResetCollection((int)arg);
                        }
                        break;
                    case BackgroundAudioConstants.AddTrack:
                        object track = new object();
                        if (e.Data.TryGetValue(BackgroundAudioConstants.AddTrack, out track))
                        {
                            // We should have the newest playlist with the new track already. If so, just repopulate the playlist.
                            Playlist.AddTracks(AudioBackgroundInterface.DeserializeAudioTracks(track.ToString()) as List<BackgroundTrackItem>);
                        }
                        break;
                    case BackgroundAudioConstants.PlayTrack: //Foreground App process has signalled that it is ready for playback
                        Debug.WriteLine("Starting Playback");
                        Object obj = new Object();
                        if (e.Data.TryGetValue(BackgroundAudioConstants.PlayTrack, out obj))
                        {
                            string s = obj as string;
                            if (!string.IsNullOrEmpty(s))
                            {
                                int t = Convert.ToInt32(s);
                                Playlist.PlayTrack(t);
                            }
                        }
                        break;
                    case BackgroundAudioConstants.RestorePlaylist: //Foreground App process updated List Track
                        Debug.WriteLine("Restoring ListTrack");
                        Playlist.PopulatePlaylist();
                        var currentTrack =
                            ApplicationSettingsHelper.ReadSettingsValue(BackgroundAudioConstants.CurrentTrack);
                        if (currentTrack == null)
                        {
                            break;
                        }
                        Playlist.CurrentTrack = (int)currentTrack;
                        break;
                    case BackgroundAudioConstants.SkipNext: // User has chosen to skip track from app context.
                        Debug.WriteLine("Skipping to next");
                        SkipToNext();
                        break;
                    case BackgroundAudioConstants.SkipPrevious: // User has chosen to skip track from app context.
                        Debug.WriteLine("Skipping to previous");
                        SkipToPrevious();
                        break;
                }
            }
        }
コード例 #12
0
 /// <summary>
 /// Fires when a message is recieved from the foreground app
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void BackgroundMediaPlayer_MessageReceivedFromForeground(object sender, MediaPlayerDataReceivedEventArgs e)
 {
     foreach (string key in e.Data.Keys)
     {
         switch (key.ToLower())
         {
             case Constants.AppSuspended:
                 Debug.WriteLine("App suspending"); // App is suspended, you can save your task state at this point
                 foregroundAppState = ForegroundAppStatus.Suspended;
                 ApplicationSettingsHelper.SaveSettingsValue(Constants.CurrentTrack, Playlist.CurrentTrackName);
                 break;
             case Constants.AppResumed:
                 Debug.WriteLine("App resuming"); // App is resumed, now subscribe to message channel
                 foregroundAppState = ForegroundAppStatus.Active;
                 break;
             case Constants.StartPlayback: //Foreground App process has signalled that it is ready for playback
                 Debug.WriteLine("Starting Playback");
                 StartPlayback();
                 break;
         }
     }
 }
コード例 #13
0
        /// <summary>
        /// Fires when a message is recieved from the foreground app
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BackgroundMediaPlayer_MessageReceivedFromForeground(object sender, MediaPlayerDataReceivedEventArgs e)
        {
            foreach (string key in e.Data.Keys)
            {
                switch (key.ToLower())
                {
                    case Constants.AppSuspended:
                        Debug.WriteLine("App suspending"); // App is suspended, you can save your task state at this point
                        foregroundAppState = ForegroundAppStatus.Suspended;
                        ApplicationSettingsHelper.SaveSettingsValue(Constants.CurrentTrack, "Teset" /*Playlist.CurrentTrackName*/);
                        break;
                    case Constants.AppResumed:
                        Debug.WriteLine("App resuming"); // App is resumed, now subscribe to message channel
                        foregroundAppState = ForegroundAppStatus.Active;
                        break;
                    case Constants.StartPlayback: //Foreground App process has signalled that it is ready for playback
                        Debug.WriteLine("Starting Playback");
                        //StartPlayback();
                        break;
                    case Constants.SkipNext: // User has chosen to skip track from app context.
                        Debug.WriteLine("Skipping to next");
                        //SkipToNext();
                        break;
                    case Constants.SkipPrevious: // User has chosen to skip track from app context.
                        Debug.WriteLine("Skipping to previous");
                        //SkipToPrevious();
                        break;
                    case Constants.AddTrack:
                        var en = e.Data.Values.GetEnumerator();
                        en.MoveNext();
                        //Playlist.Tracks.Add(en.Current.ToString());

                        currentMediaPath = en.Current.ToString();
                        BackgroundMediaPlayer.Current.AutoPlay = false;
                        BackgroundMediaPlayer.Current.SetUriSource(new Uri(currentMediaPath));
                        BackgroundMediaPlayer.Current.Play();

                        systemmediatransportcontrol.PlaybackStatus = MediaPlaybackStatus.Playing;
                        systemmediatransportcontrol.DisplayUpdater.Type = MediaPlaybackType.Music;
                        systemmediatransportcontrol.DisplayUpdater.MusicProperties.Title = "Test 1234567890 123456789";
                        systemmediatransportcontrol.DisplayUpdater.Update();
                        break;
                }
            }
        }
コード例 #14
0
 private void BackgroundMediaPlayer_MessageReceivedFromForeground(object sender, MediaPlayerDataReceivedEventArgs e)
 {
     foreach (string key in e.Data.Keys)
     {
         switch (key.ToLower())
         {
             case ConstantValues.AppSuspended:
                 _foregroundAppState = ForegroundAppStatus.Suspended;
                 ApplicationSettingsHelper.SaveSettingsValue(ConstantValues.CurrentTrack, _queue.CurrentTrack.Name);
                 break;
             case ConstantValues.AppResumed:
                 _foregroundAppState = ForegroundAppStatus.Active;
                 break;
             case ConstantValues.StartPlayback:
                 Debug.WriteLine("Start playback message received from foreground");
                 UpdateQueue();
                 StartPlayback();
                 break;
             case ConstantValues.SkipNext:
                 SkipToNext();
                 break;
             case ConstantValues.SkipPrevious:
                 SkipToPrevious();
                 break;
             case ConstantValues.RefreshPlaylist:
                 UpdateQueue(true);
                 BackgroundMediaPlayer.Current.Pause();
                 _queue.StartPlaying();
                 BackgroundMediaPlayer.Current.Play();
                 break;
         }
     }
 }
コード例 #15
0
        /// <summary>
        /// Fires when a message is recieved from the foreground app
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BackgroundMediaPlayer_MessageReceivedFromForeground(object sender, MediaPlayerDataReceivedEventArgs e)
        {
            foreach (string key in e.Data.Keys)
            {
                switch (key.ToLower())
                {
                case BackgroundAudioConstants.PingBackground:
                    Debug.WriteLine("Received Ping from foreground");     // App is suspended, you can save your task state at this point
                    ValueSet message = new ValueSet();
                    message.Add(BackgroundAudioConstants.PingBackground, DateTime.Now.ToString());
                    BackgroundMediaPlayer.SendMessageToForeground(message);
                    break;

                case BackgroundAudioConstants.AppSuspended:
                    Debug.WriteLine("App suspending");     // App is suspended, you can save your task state at this point
                    foregroundAppState = ForegroundAppStatus.Suspended;
                    ApplicationSettingsHelper.SaveSettingsValue(BackgroundAudioConstants.CurrentTrack, Playlist.CurrentTrackIndex);
                    break;

                case BackgroundAudioConstants.AppResumed:
                    Debug.WriteLine("App resuming");     // App is resumed, now subscribe to message channel
                    foregroundAppState = ForegroundAppStatus.Active;
                    break;

                case BackgroundAudioConstants.StartPlayback:     //Foreground App process has signalled that it is ready for playback
                    Debug.WriteLine("Starting Playback");
                    StartPlayback();
                    break;

                case BackgroundAudioConstants.UpdatePlaylist:
                    Debug.WriteLine("Updating playlist...");
                    Playlist.UpdatePlaylist();
                    break;

                case BackgroundAudioConstants.ResetPlaylist:
                    var arg = new object();
                    if (e.Data.TryGetValue(BackgroundAudioConstants.ResetPlaylist, out arg))
                    {
                        Playlist.ResetCollection((int)arg);
                    }
                    break;

                case BackgroundAudioConstants.AddTrack:
                    object track = new object();
                    if (e.Data.TryGetValue(BackgroundAudioConstants.AddTrack, out track))
                    {
                        // We should have the newest playlist with the new track already. If so, just repopulate the playlist.
                        Playlist.AddTracks(AudioBackgroundInterface.DeserializeAudioTracks(track.ToString()) as List <BackgroundTrackItem>);
                    }
                    break;

                case BackgroundAudioConstants.PlayTrack:     //Foreground App process has signalled that it is ready for playback
                    Debug.WriteLine("Starting Playback");
                    Object obj = new Object();
                    if (e.Data.TryGetValue(BackgroundAudioConstants.PlayTrack, out obj))
                    {
                        string s = obj as string;
                        if (!string.IsNullOrEmpty(s))
                        {
                            int t = Convert.ToInt32(s);
                            Playlist.PlayTrack(t);
                        }
                    }
                    break;

                case BackgroundAudioConstants.RestorePlaylist:     //Foreground App process updated List Track
                    Debug.WriteLine("Restoring ListTrack");
                    Playlist.PopulatePlaylist();
                    var currentTrack =
                        ApplicationSettingsHelper.ReadSettingsValue(BackgroundAudioConstants.CurrentTrack);
                    if (currentTrack == null)
                    {
                        break;
                    }
                    Playlist.CurrentTrack = (int)currentTrack;
                    break;

                case BackgroundAudioConstants.SkipNext:     // User has chosen to skip track from app context.
                    Debug.WriteLine("Skipping to next");
                    SkipToNext();
                    break;

                case BackgroundAudioConstants.SkipPrevious:     // User has chosen to skip track from app context.
                    Debug.WriteLine("Skipping to previous");
                    SkipToPrevious();
                    break;
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// Fires when a message is recieved from the foreground app
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BackgroundMediaPlayer_MessageReceivedFromForeground(object sender, MediaPlayerDataReceivedEventArgs e)
        {
            foreach (var one in e.Data)
            {
                string key = one.Key;
                switch (key.ToLower())
                {
                case Constants.AppSuspended:
                    Debug.WriteLine("App suspending");     // App is suspended, you can save your task state at this point
                    foregroundAppState = ForegroundAppStatus.Suspended;
                    ApplicationSettingsHelper.SaveSettingsValue(Constants.CurrentTrack, Playlist.CurrentTrackName);
                    break;

                case Constants.AppResumed:
                    Debug.WriteLine("App resuming");     // App is resumed, now subscribe to message channel
                    foregroundAppState = ForegroundAppStatus.Active;
                    break;

                case Constants.Trackat:     // User has chosen to skip track from app context.
                    foregroundAppState = ForegroundAppStatus.Active;
                    Debug.WriteLine("play to Trackat");
                    Trackat(one.Value.ToString());
                    break;

                case Constants.StartPlayback:     //Foreground App process has signalled that it is ready for playback
                    foregroundAppState = ForegroundAppStatus.Active;
                    Debug.WriteLine("Starting Playback");
                    StartPlayback();
                    break;

                case Constants.SkipNext:     // User has chosen to skip track from app context.
                    foregroundAppState = ForegroundAppStatus.Active;
                    Debug.WriteLine("Skipping to next");
                    SkipToNext();
                    break;

                case Constants.SkipPrevious:     // User has chosen to skip track from app context.
                    foregroundAppState = ForegroundAppStatus.Active;
                    Debug.WriteLine("Skipping to previous");
                    SkipToPrevious();
                    break;

                case Constants.conCurrentFile:
                    Debug.WriteLine("Play current File");
                    object value = string.Empty;
                    bool   rev   = e.Data.TryGetValue(Constants.conCurrentFile, out value);
                    if (rev)
                    {
                        string fileToken = value.ToString();
                        StartFile(fileToken);
                    }
                    break;

                case Constants.conPlaySingleFile:
                    object v  = string.Empty;
                    bool   bl = e.Data.TryGetValue(Constants.conPlaySingleFile, out v);
                    if (bl)
                    {
                        string fileToken = v.ToString();
                        StartSingleFile(fileToken);
                    }
                    break;

                case Constants.conPlayByIndex:
                    object vByindex = string.Empty;
                    bool   bplay    = e.Data.TryGetValue(Constants.conPlayByIndex, out vByindex);
                    if (bplay)
                    {
                        int index = Convert.ToInt32(vByindex);
                        StartPlayback(index);
                    }
                    break;
                }
            }
        }