Ejemplo n.º 1
0
        void HandleMediaPlayerMediaOpened(MediaPlayer sender, object args)
        {
            if (isFirstOpen)
            {
                isFirstOpen = false;
                double percentage = ApplicationSettings.GetSettingsValue<double>(ApplicationSettings.CURRENT_TRACK_PERCENTAGE, 0.0);
                ApplicationSettings.PutSettingsValue(ApplicationSettings.CURRENT_TRACK_PERCENTAGE, 0.0);

                if (percentage > 0)
                {
                    Logger.Current.Init(LogType.PlayAction);

                    Logger.Current.Log(new CallerInfo(), LogLevel.Info, "Length Total {0}", mediaPlayer.NaturalDuration.Ticks);

                    mediaPlayer.Position = TimeSpan.FromTicks((long)(mediaPlayer.NaturalDuration.Ticks * percentage));
                }
            }

            int trackId = ApplicationSettings.GetSettingsValue<int>(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, 0);
            Logger.Current.Init(LogType.PlayAction);

            Logger.Current.Log(new CallerInfo(), LogLevel.Info, "Trying to play row {0}", trackId);

            playingTrack = TrackInfo.TrackInfoFromRowId(trackId);
            TrackChanged.Invoke(this, playingTrack);

            if (playAfterOpen)
            {
                sender.Play();
            }
            else
            {
                playAfterOpen = true;
            }
        }
Ejemplo n.º 2
0
        private async Task UpdateTile(TrackInfo args)
        {
            if (args == null)
            {
                TileUpdateManager.CreateTileUpdaterForApplication("App").Clear();
            }
            else
            {
                string artPath = string.Empty;
                if (!string.IsNullOrEmpty(args.ArtPath))
                {
                    IStorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(args.ArtPath);

                    artPath = file.Path;
                }

                XmlDocument tileTemplate = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150PeekImageAndText01);

                XmlNodeList textAttributes = tileTemplate.GetElementsByTagName("text");

                textAttributes[0].AppendChild(tileTemplate.CreateTextNode(args.Title));
                textAttributes[1].AppendChild(tileTemplate.CreateTextNode(args.Artist));
                textAttributes[2].AppendChild(tileTemplate.CreateTextNode(args.Album));

                XmlNodeList imageAttribute = tileTemplate.GetElementsByTagName("image");
                XmlElement imageElement = (XmlElement)imageAttribute[0];
                imageElement.SetAttribute("src", artPath);

                // Create the notification from the XML.
                var tileNotification = new TileNotification(tileTemplate);

                try
                {
                    TileUpdateManager.CreateTileUpdaterForApplication("App").Update(tileNotification);
                }
                catch (Exception)
                {
                }
            }

        }
Ejemplo n.º 3
0
        /// <summary>
        /// Tries to play the track with TrackInfo. If MakeActive is false, doesn't start playback just
        /// moves the play queue to that track
        /// </summary>
        /// <param name="trackInfo"></param>
        /// <param name="makeActive"></param>
        /// <returns></returns>
        async Task PlayTrack(TrackInfo trackInfo, bool makeActive)
        {
            try
            {
                StorageFile file = await StorageFile.GetFileFromPathAsync(trackInfo.Path);

                if (!makeActive)
                {
                    playAfterOpen = false;
                }
                else
                {
                    isFirstOpen = true;
                }

                mediaPlayer.SetFileSource(file);
                IsActive = makeActive;
            }
            catch (UnauthorizedAccessException ex)
            {
                Logger.Current.Log(new CallerInfo(), LogLevel.Error, "Couldn't play track {0} got UnauthorizedAccessException message {1}", trackInfo.SongId, ex.Message);

                IsActive = false;

                PlayNext();
            }
            catch (FileNotFoundException ex)
            {
                Logger.Current.Log(new CallerInfo(), LogLevel.Error, "Couldn't play track {0} got FileNotFoundException message {1}", trackInfo.SongId, ex.Message);

                IsActive = false;

                PlayNext();
            }
        }
Ejemplo n.º 4
0
        private async void HandlePlayQueueTrackChanged(PlayQueueManager sender, TrackInfo args)
        {
            int newRowId = 0;
            Logger.Current.Init(LogType.AudioFunction);

            Logger.Current.Log(new CallerInfo(), LogLevel.Info, "Track changed, args set? {0}", args != null);

            if (args != null)
            {
                systemMediaTransportControls.PlaybackStatus = MediaPlaybackStatus.Playing;

                systemMediaTransportControls.DisplayUpdater.Type = MediaPlaybackType.Music;
                systemMediaTransportControls.DisplayUpdater.MusicProperties.Title = args.Title;
                systemMediaTransportControls.DisplayUpdater.MusicProperties.Artist = args.Artist;
                systemMediaTransportControls.DisplayUpdater.MusicProperties.AlbumArtist = args.AlbumArtist;

                systemMediaTransportControls.IsNextEnabled = (args.NextId > 0);
                systemMediaTransportControls.IsPreviousEnabled = (args.PrevId > 0);

                newRowId = args.RowId;
            }
            else
            {
                systemMediaTransportControls.PlaybackStatus = MediaPlaybackStatus.Stopped;
            }

            if (foregroundTaskState == ForegroundTaskState.Running)
            {
                Logger.Current.Init(LogType.AudioFunction);

                Logger.Current.Log(new CallerInfo(), LogLevel.Info, "Alerting FG of track change {0}", newRowId);

                PlayQueueManager.Current.SendMessageToForeground(PlayQueueConstantBGMessageId.TrackChanged, newRowId);
            }

            systemMediaTransportControls.DisplayUpdater.Update();

            await UpdateTile(args);
        }