示例#1
0
        /// <summary>
        /// Sends message to background informing app has resumed
        /// Subscribe to MediaPlayer events
        /// </summary>
        void ForegroundApp_Resuming(object sender, object e)
        {
            ApplicationSettingsHelper.SaveSettingsValue(ApplicationSettingsConstants.AppState, AppState.Active.ToString());

            // Verify the task is running
            if (IsMyBackgroundTaskRunning)
            {
                // If yes, it's safe to reconnect to media play handlers
                AddMediaPlayerEventHandlers();

                // Send message to background task that app is resumed so it can start sending notifications again
                MessageService.SendMessageToBackground(new AppResumedMessage());

                UpdateTransportControls(CurrentPlayer.CurrentState);

                int trackId = GetCurrentTrackIdAfterAppResume();

                CurrentTrack = trackId == 0 ? null : TrackQueue.Single(s => s.InternalID == trackId);
            }
            else
            {
                StopButtonVisibility = Visibility.Collapsed;
                PlayButtonVisibility = Visibility.Visible;
                PlayButtonIsEnabled  = true;
            }

            RefreshBindings();
        }
        private int GetIndexOfCurrentTrack()
        {
            if (CurrentTrack == null)
            {
                return(0);
            }

            return(TrackQueue.ToList().FindIndex(m => m.InternalID == CurrentTrack.InternalID));
        }
        public void ClearQueue(string QueueName)
        {
            try
            {
                TrackQueue queue = (TrackQueue)ResourceManager.GetResource(QueueName);

                queue.Clear();
            }
            catch (Exception ex)
            {
                LOG.Error(string.Format("QueueService清空队列出错:{0},位置{1}", QueueName, ex.Message));
            }
        }
        public void RemoveQueue(string QueueName, Int16 index)
        {
            try
            {
                TrackQueue queue = (TrackQueue)ResourceManager.GetResource(QueueName);

                queue.TakeOutAt(index);
            }
            catch (Exception ex)
            {
                LOG.Error(string.Format("QueueService移出队列出错:{0},位置{1}", QueueName, index, ex.Message));
            }
        }
        public void EntryQueue(string QueueName, Int16 index, string ItemID)
        {
            try
            {
                TrackQueue queue = (TrackQueue)ResourceManager.GetResource(QueueName);

                queue.InsertByIndex(index, ItemID);
            }
            catch (Exception ex)
            {
                LOG.Error(string.Format("QueueService增加队列出错:{0},位置{1},字段{2}", QueueName, index, ItemID, ex.Message));
            }
        }
        public string[] GetQueueItems(string QueueName)
        {
            try
            {
                TrackQueue queue = (TrackQueue)ResourceManager.GetResource(QueueName);

                return(queue.ListItemID());
            }
            catch (Exception ex)
            {
                LOG.Error(string.Format("QueueService获取队列{0}项目ID出错:{1}", QueueName, ex.Message));
                return(null);
            }
        }
        public string GetQueueItemCounts(string QueueName)
        {
            try
            {
                TrackQueue queue = (TrackQueue)ResourceManager.GetResource(QueueName);

                return(queue.Counts.ToString());
            }
            catch (Exception ex)
            {
                LOG.Error(string.Format("QueueService获取队列{0}数量出错:{1}", QueueName, ex.Message));
                return(null);
            }
        }
        public async Task UpdateTrackQueue()
        {
            TrackQueue = await MixDataHandler.instance.GetMixes(true);

            if (CurrentTrack != null && CurrentTrack.Playing)
            {
                CurrentTrack = TrackQueue.Where(x => x.InternalID == CurrentTrack.InternalID).FirstOrDefault();

                if (CurrentTrack != null)
                {
                    CurrentTrack.Playing = true;
                }
            }
        }
        public string GetQueueItemType(string QueueName)
        {
            try
            {
                TrackQueue queue = (TrackQueue)ResourceManager.GetResource(QueueName);

                //return queue.ItemType;
                return(null); // DongMin改,为了编译通过
            }
            catch (Exception ex)
            {
                LOG.Error(string.Format("QueueService获取队列{0}项目类型出错:{1}", QueueName, ex.Message));
                return(null);
            }
        }
示例#10
0
        /// <summary>
        /// This event is raised when a message is recieved from BackgroundAudioTask
        /// </summary>
        async void BackgroundMediaPlayer_MessageReceivedFromBackground(object sender, MediaPlayerDataReceivedEventArgs e)
        {
            TrackChangedMessage trackChangedMessage;

            if (MessageService.TryParseMessage(e.Data, out trackChangedMessage))
            {
                // When foreground app is active change track based on background message
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // If playback stopped then clear the UI
                    if (trackChangedMessage.InternalMixID == 0)
                    {
                        Stop();
                        RefreshBindings();

                        return;
                    }

                    CurrentTrack = TrackQueue.Single(s => s.InternalID == trackChangedMessage.InternalMixID);

                    // Ensure track buttons are re-enabled since they are disabled when pressed
                    foreach (Mix m in TrackQueue.Where(m => m.Playing))
                    {
                        m.Playing = false;
                    }

                    CurrentTrack.Playing = true;

                    NextButtonIsEnabled     = true;
                    PreviousButtonIsEnabled = true;
                    RefreshBindings();
                });

                return;
            }

            BackgroundAudioTaskStartedMessage backgroundAudioTaskStartedMessage;

            if (MessageService.TryParseMessage(e.Data, out backgroundAudioTaskStartedMessage))
            {
                // StartBackgroundAudioTask is waiting for this signal to know when the task is up and running
                // and ready to receive messages
                Debug.WriteLine("BackgroundAudioTask started");
                return;
            }

            UpdateMediaPlayerInfoMessage updateMediaPlayerInfoMessage;

            if (MessageService.TryParseMessage(e.Data, out updateMediaPlayerInfoMessage))
            {
                // StartBackgroundAudioTask is waiting for this signal to know when the task is up and running
                // and ready to receive messages
                // When foreground app is active change track based on background message
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    if (MainpageViewModel.instance.GetMixesTask != null && MainpageViewModel.instance.GetMixesTask.IsCompleted == false)
                    {
                        await MainpageViewModel.instance.GetMixesTask;
                    }

                    if (updateMediaPlayerInfoMessage.InternalMixID != 0)
                    {
                        if (TrackQueue == null)
                        {
                            TrackQueue = MainpageViewModel.instance.Mixes;
                        }

                        Mix PlayingTrack = CurrentTrack;
                        CurrentTrack     = TrackQueue.Where(s => s.InternalID == updateMediaPlayerInfoMessage.InternalMixID).FirstOrDefault();

                        if (CurrentTrack == null)
                        {
                            CurrentTrack = PlayingTrack;
                        }

                        // Ensure track buttons are re-enabled since they are disabled when pressed
                        foreach (Mix m in TrackQueue.Where(m => m.Playing))
                        {
                            if (m != CurrentTrack)
                            {
                                m.Playing = false;
                            }
                        }

                        if (CurrentTrack != null)
                        {
                            CurrentTrack.Playing = true;

                            NextButtonIsEnabled     = true;
                            PreviousButtonIsEnabled = true;
                            RefreshBindings();
                        }
                    }
                });

                Debug.WriteLine("Updating MediaInfo");
                return;
            }
        }
        //void EntryQueue(string QueueName, string ItemID)
        //{

        //}

        //string ExitQueue(string QueueName)
        //{ }

        //public string[] GetBatteryStatusByTrayID(string TrayID)
        //{
        //    try
        //    {
        //        //TrackQueue queue = (TrackQueue)ResourceManager.GetResource(QueueName);
        //        //return queue.ListItemID();
        //        //TrackQueue _proxy= new TrackQueue("");
        //        ////string[] _batteryStatus=new string[48];
        //        //return _proxy.GetBatteryInfoByTrayID(TrayID);

        //        Tray tray = new Tray();
        //        return tray.GetBatteryIDs(TrayID);

        //    }

        //    catch (Exception ex)
        //    {
        //        LOG.Error(string.Format("分选机获取电池信息出错:{0}",  ex.Message));
        //        return null;
        //    }
        //}

        //public string[] GetBIMBatteryByTrayID(string TrayID)
        //{
        //    try
        //    {
        //        Tray tray = new Tray();
        //        return tray.GetBIMBatteryIDs(TrayID);
        //    }

        //    catch (Exception ex)
        //    {
        //        LOG.Error(string.Format("分选机获取电池信息出错:{0}",  ex.Message));
        //        return null;
        //    }
        //}

        public string[] GetBIMTrayIDs(string queueName)
        {
            TrackQueue queue = (TrackQueue)ResourceManager.GetResource(queueName);

            return(queue.ListItemID());
        }
示例#12
0
 /// <summary>
 /// Clears all items from the Track and Engage request queues, anything not already sent to the Mixpanel
 /// API will no longer be sent
 /// </summary>
 public static void Clear()
 {
     TrackQueue.Clear();
     EngageQueue.Clear();
 }