예제 #1
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            string taskId = taskInstance.InstanceId.ToString();

            MobileDebug.Service.SetIsBackground(taskId);
            MobileDebug.Service.WriteEventPair("Run", "task == null", task == null,
                                               "this.Hash", GetHashCode(), "PlayerHash", BackgroundMediaPlayer.Current.GetHashCode());

            deferral = taskInstance.GetDeferral();
            taskInstance.Canceled       += OnCanceled;
            taskInstance.Task.Completed += TaskCompleted;

            Unsubscribe(task);

            saveLoad = new AutoSaveLoad(completeFileName, backupFileName, simpleFileName);
            library  = await saveLoad.LoadSimple(false);

            lsh  = LibrarySubscriptionsHandler.GetInstance(library);
            smtc = SystemMediaTransportControls.GetForCurrentView();
            task = this;

            musicPlayer = new MusicPlayer(smtc, library);
            ringer      = new Ringer(this, library);

            await saveLoad.LoadComplete(library);

            saveLoad.Add(library);

            Subscribe(task);

            await BackgroundPlayer.SetCurrent();

            MobileDebug.Service.WriteEventPair("RunFinish", "This", GetHashCode(), "Lib", library.GetHashCode());
        }
예제 #2
0
        public MusicPlayer(SystemMediaTransportControls smtControls, ILibrary library)
        {
            smtc         = smtControls;
            this.library = library;

            lsh = LibrarySubscriptionsHandler.GetInstance(library);
            lsh.CurrentPlaylist.CurrentSongPositionChanged += OnCurrentSongPositionChanged;
            lsh.CurrentPlaylist.CurrentSong.ArtistChanged  += OnCurrentSongArtistOrTitleChanged;
            lsh.CurrentPlaylist.CurrentSong.TitleChanged   += OnCurrentSongArtistOrTitleChanged;

            timer = new Timer(Timer_Tick, null, Timeout.Infinite, Timeout.Infinite);

            ActivateSystemMediaTransportControl();
            SetNextSongIfMediaEndedNotHappens();
        }
예제 #3
0
        public void Add(ILibrary lib)
        {
            sh = LibrarySubscriptionsHandler.GetInstance(lib);

            sh.IsPlayingChanged                             += OnPlayStateChanged;
            sh.CurrentPlaylistChanged                       += OnCurrentPlaylistChanged;
            sh.PlaylistsPropertyChanged                     += OnPlaylistsPropertyChanged;
            sh.PlaylistCollectionChanged                    += OnPlaylistCollectionChanged;
            sh.AllPlaylists.LoopChanged                     += AllPlaylists_LoopChanged;
            sh.AllPlaylists.ShuffleChanged                  += AllPlaylists_ShuffleChanged;
            sh.AllPlaylists.ShuffleCollectionChanged        += AllPlaylists_ShuffleCollectionChanged;
            sh.AllPlaylists.SongsPropertyChanged            += AllPlaylists_SongsPropertyChanged;
            sh.AllPlaylists.SongCollectionChanged           += AllPlaylists_SongCollectionChanged;
            sh.AllPlaylists.AllSongs.SomethingChanged       += AllPlaylists_AllSongs_SomethingChanged;
            sh.CurrentPlaylist.CurrentSongChanged           += CurrentPlaylist_CurrentSongChanged;
            sh.CurrentPlaylist.CurrentSongPositionChanged   += CurrentPlaylist_CurrentSongPositionChanged;
            sh.CurrentPlaylist.AllSongs.SomethingChanged    += CurrentPlaylist_AllSongs_SomethingChanged;
            sh.CurrentPlaylist.CurrentSong.SomethingChanged += CurrentPlaylist_CurrentSong_SomethingChanged;
            sh.OtherPlaylists.CurrentSongPositionChanged    += OtherPlaylists_CurrentSongPositionChanged;
        }
예제 #4
0
        public BackForegroundCommunicator(ILibrary library)
        {
            receivingItems = new List <Tuple <int, ValueSet> >();
            receivers      = GetAllReceiver().ToDictionary(r => r.Key);
            lsh            = LibrarySubscriptionsHandler.GetInstance(library);

            this.library = library;

            if (library.IsForeground)
            {
                BackgroundMediaPlayer.MessageReceivedFromBackground += BackgroundMediaPlayer_MessageReceived;
                senderMethod = BackgroundMediaPlayer.SendMessageToBackground;

                GetLibrary();
            }
            else
            {
                BackgroundMediaPlayer.MessageReceivedFromForeground += BackgroundMediaPlayer_MessageReceived;
                senderMethod = BackgroundMediaPlayer.SendMessageToForeground;

                lsh.SkippedSong += OnSkippedSong;
            }

            lsh.Loaded += OnLoaded;
            lsh.CurrentPlaylistChanged                  += OnCurrentPlaylistChanged;
            lsh.PlaylistsPropertyChanged                += OnPlaylistsPropertyChanged;
            lsh.PlaylistCollectionChanged               += OnPlaylistCollectionChanged;
            lsh.IsPlayingChanged                        += OnIsPlayingChanged;
            lsh.PlayerStateChanged                      += OnPlayerStateChanged;
            lsh.AllPlaylists.CurrentSongChanged         += OnAllPlaylists_CurrentSongChanged;
            lsh.AllPlaylists.CurrentSongPositionChanged += OnAllPlaylists_CurrentSongPositionChanged;
            lsh.AllPlaylists.LoopChanged                += OnAllPlaylists_LoopChanged;
            lsh.AllPlaylists.SongsPropertyChanged       += OnAllPlaylists_SongsPropertyChanged;
            lsh.AllPlaylists.SongCollectionChanged      += OnAllPlaylists_SongCollectionChanged;
            lsh.AllPlaylists.ShuffleChanged             += OnAllPlaylists_ShuffleChanged;
            lsh.AllPlaylists.ShuffleCollectionChanged   += OnAllPlaylists_ShuffleCollectionChanged;
            lsh.AllPlaylists.AllSongs.ArtistChanged     += OnAllPlaylists_AllSongs_ArtistChanged;
            lsh.AllPlaylists.AllSongs.TitleChanged      += OnAllPlaylist_AllSongs_TitleChanged;
            lsh.AllPlaylists.AllSongs.DurationChanged   += OnAllPlaylists_AllSongs_DurationChanged;
        }