public void Handle(AudioTrackEdited message)
        {
            AudioObj fromBackgroundAudio = this.GetCurrentTrackFromBackgroundAudio();

            if (fromBackgroundAudio != null && message.OwnerId == fromBackgroundAudio.owner_id && message.Id == fromBackgroundAudio.id)
            {
                fromBackgroundAudio.artist = message.Artist;
                fromBackgroundAudio.title  = message.Title;
            }
            AudioTrack track     = BGAudioPlayerWrapper.Instance.Track;
            long?      nullable1 = track != null ? new long?(track.GetTagOwnerId()) : new long?();
            string     str       = track != null?track.GetTagId() : null;

            if (str != null && ((IEnumerable <char>)str).Contains <char>('_'))
            {
                str = str.Substring(str.IndexOf('_') + 1);
            }
            if (track != null)
            {
                long?nullable2      = nullable1;
                long valueOrDefault = nullable2.GetValueOrDefault();
                if ((message.OwnerId == valueOrDefault ? (nullable2.HasValue ? 1 : 0) : 0) != 0 && message.Id.ToString() == str)
                {
                    track.BeginEdit();
                    track.Artist = message.Artist;
                    track.Title  = message.Title;
                    track.EndEdit();
                }
            }
            this.NotifyPropertyChanged <string>((Expression <Func <string> >)(() => this.ArtistName));
            this.NotifyPropertyChanged <string>((Expression <Func <string> >)(() => this.TrackName));
            this.NotifyPropertyChanged <string>((Expression <Func <string> >)(() => this.CurrentTrackStr));
        }
Beispiel #2
0
        private void lbiNewSession_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if ((settings.WarnOnNew) && (App.IsResumeAvailable))
            {
                // If resume is available, prompt the user to make sure.
                MessageBoxResult result = MessageBox.Show(AppResources.WarnOnNewText, AppResources.WarnOnNewTitle, MessageBoxButton.OKCancel);

                // If user says ok, stop the BAP and set flag indicating that new session has been started.
                if (result == MessageBoxResult.OK)
                {
                    BackgroundAudioPlayer.Instance.Stop();

                    // Need to detach track before you can edit it's properties.
                    AudioTrack currTrack = BackgroundAudioPlayer.Instance.Track;
                    BackgroundAudioPlayer.Instance.Track = null;

                    // Append "_new" to indicate to background player that a new session should be started.
                    currTrack.BeginEdit();
                    currTrack.Tag += "_new";
                    currTrack.EndEdit();

                    BackgroundAudioPlayer.Instance.Track = currTrack;
                }
                else // Don't want to navigate so return if the user cancelled the prompt.
                {
                    return;
                }
            }

            this.NavigationService.Navigate(new Uri("/SessionPage.xaml?SessionType=New", UriKind.Relative));
        }
        public static AudioTrack ToAudioTrack(this PlaylistItem playlistItem)
        {
            var result = new AudioTrack();

            result.BeginEdit();

            result.Source   = new Uri(playlistItem.TrackUrl, UriKind.Absolute);
            result.Title    = playlistItem.TrackName;
            result.Artist   = playlistItem.Artist;
            result.Album    = playlistItem.Album;
            result.AlbumArt = !string.IsNullOrEmpty(playlistItem.ImageUrl) ? new Uri(playlistItem.ImageUrl, UriKind.Absolute) : null;

            result.EndEdit();

            return(result);
        }
        private void bookSelectionChange(int selectedIndex)
        {
            App.player.selectedBookIndex = selectedIndex;
            bookPicker.SelectedIndex     = selectedIndex;
            try
            {
                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (App.player.selectedBook.files.Count <= 0 || !isoStore.FileExists(App.player.selectedBook.files.First()))
                    {
                        return;
                    }
                }


                if (BackgroundAudioPlayer.Instance.Track != null && BackgroundAudioPlayer.Instance.Track.Tag.Contains(App.player.selectedBook.files.First()))
                {
                    return;
                }
                BackgroundAudioPlayer.Instance.Pause();
                AudioTrack track = new AudioTrack(new Uri(App.player.selectedBook.files.First(), UriKind.Relative),
                                                  App.player.selectedBook.BookTitle, App.player.selectedBook.Author, "", null);
                track.BeginEdit();
                track.Tag = "clarible@" + App.player.selectedBook.files.First() + "@" + App.player.selectedBook.BookTitle;
                track.EndEdit();
                BackgroundAudioPlayer.Instance.Track    = track;
                BackgroundAudioPlayer.Instance.Position = new TimeSpan(0, 0, App.player.selectedBook.getPosition());
                timer.Stop();
                timer.Start();
                BackgroundAudioPlayer.Instance.Pause();
            }
            catch (Exception error)
            {
            }
            updateUI();
        }
        /// <summary>
        /// Called when the playstate changes, except for the Error state (see OnError)
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time the playstate changed</param>
        /// <param name="playState">The new playstate of the player</param>
        /// <remarks>
        /// Play State changes cannot be cancelled. They are raised even if the application
        /// caused the state change itself, assuming the application has opted-in to the callback.
        ///
        /// Notable playstate events:
        /// (a) TrackEnded: invoked when the player has no current track. The agent can set the next track.
        /// (b) TrackReady: an audio track has been set and it is now ready for playack.
        ///
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            switch (playState)
            {
            case PlayState.TrackEnded:
                if (currentPlaylist.Count > 0)
                {
                    player.Track = GetNextTrack();
                }
                break;

            case PlayState.TrackReady:
                track.BeginEdit();
                track.Title = currentPlaylist[currentTrackNumber].Title;
                track.EndEdit();
                player.Play();
                break;

            case PlayState.Shutdown:
                // TODO: Handle the shutdown state here (e.g. save state)
                player.Close();
                break;

            case PlayState.Unknown:
                break;

            case PlayState.Stopped:
                break;

            case PlayState.Paused:
                break;

            case PlayState.Playing:
                break;

            case PlayState.BufferingStarted:
                track.BeginEdit();
                track.Title = "Buffering...";
                track.EndEdit();
                break;

            case PlayState.BufferingStopped:
                track.BeginEdit();
                track.Title = currentPlaylist[currentTrackNumber].Title;
                track.EndEdit();
                break;

            case PlayState.Rewinding:
                track.BeginEdit();
                track.Title = "Rewinding...";
                track.EndEdit();
                break;

            case PlayState.FastForwarding:
                track.BeginEdit();
                track.Title = "FastForwarding...";
                track.EndEdit();
                break;
            }

            NotifyComplete();
        }
Beispiel #6
0
        static void GetListWebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            try
            {
                StreamReader    sR   = new StreamReader(e.Result);
                string          html = sR.ReadToEnd();
                int             playListCount;
                string          pattern;
                MatchCollection matches;
                AudioTrack      t;

                #region getAlbumAndArtist
                pattern       = @"track-album.>(.+)-(.+)</a>";
                matches       = Regex.Matches(@html, pattern);
                playListCount = matches.Count;
                for (int i = 0; i < playListCount; i++)
                {
                    t = new AudioTrack();
                    t.BeginEdit();
                    t.Album  = matches[i].Groups[1].ToString();
                    t.Artist = matches[i].Groups[2].ToString();
                    t.EndEdit();
                    playList.Add(t);
                }
                #endregion

                #region getList
                pattern = @"http\S+01.mp3";
                Match  matche = Regex.Match(html, pattern);
                string title  = matche.ToString().Replace(@"\", null);
                title = title.Remove(title.Length - 6);
                for (int i = 0; i < playListCount; i++)
                {
                    playList[i].BeginEdit();
                    if (i + 1 < 10)
                    {
                        playList[i].Source = new Uri(title + "0" + (i + 1).ToString() + ".mp3");
                    }
                    else
                    {
                        playList[i].Source = new Uri(title + (i + 1).ToString() + ".mp3");
                    }
                    playList[i].EndEdit();
                }
                #endregion

                #region getMusicTitleAndMusicCover
                pattern = @"img alt=.(.+). src=.(http://img.luoo.net/\S+60x60.jpg)";
                matches = Regex.Matches(@html, pattern);
                for (int i = 0; i < playListCount; i++)
                {
                    t = playList[i];
                    t.BeginEdit();
                    t.Title = matches[i].Groups[1].ToString();
                    t.Tag   = currentAlbumNumber + "|" + matches[i].Groups[2].ToString();
                    t.EndEdit();
                }
                #endregion

                #region getAlbumCover
                pattern = @"http://img.luoo.net/\S+640x452.jpg";
                matches = Regex.Matches(@html, pattern);
                Uri cover = new Uri(matches[0].ToString(), UriKind.Absolute);
                for (int i = 0; i < playListCount; i++)
                {
                    playList[i].BeginEdit();
                    playList[i].AlbumArt = cover;
                    playList[i].EndEdit();
                }
                #endregion

                #region getAlbumTitle
                pattern = @"<title>(\S+)</title>";
                matches = Regex.Matches(@html, pattern);
                string temp = "|" + matches[0].Groups[1].ToString();
                for (int i = 0; i < playListCount; i++)
                {
                    playList[i].BeginEdit();
                    playList[i].Tag += temp;
                    playList[i].EndEdit();
                }
                #endregion

                //
                sR.Close();
            }
            catch
            {
                //throw new Exception();
                playList.Add(new AudioTrack(new Uri("http://www.baidu.com"), "error", null, null, null));
            }
            currentTrackNumber = 0;
            manulResetEvent.Set();
        }
Beispiel #7
0
        async Task RunStreamingAsync(AudioTrack track, AudioStreamer streamer)
        {
            IMediaStreamFacade mediaStreamFacade = null;

            try
            {
                if (null == track || null == track.Tag)
                {
                    Debug.WriteLine("AudioTrackStreamer.RunStreamingAsync() null url");
                    return;
                }

                Uri url;
                if (!Uri.TryCreate(track.Tag, UriKind.Absolute, out url))
                {
                    Debug.WriteLine("AudioTrackStreamer.RunStreamingAsync() invalid url: " + track.Tag);
                    return;
                }

                var defaultTitle = "Unknown";

                var mediaTrack = TrackManager.Tracks.Where(t => null != t).FirstOrDefault(t => t.Url == url);

                if (null != mediaTrack)
                    defaultTitle = mediaTrack.Title;

                _metadataHandler.DefaultTitle = defaultTitle;

                if (!string.Equals(track.Title, defaultTitle))
                {
                    track.BeginEdit();
                    track.Title = defaultTitle;
                    track.EndEdit();
                }

                mediaStreamFacade = await InitializeMediaStreamAsync().ConfigureAwait(false);

                Debug.Assert(null != mediaStreamFacade);

                MediaStreamSource mss;
                if (null != mediaTrack)
                    mss = await mediaStreamFacade.CreateMediaStreamSourceAsync(mediaTrack, _cancellationTokenSource.Token).ConfigureAwait(false);
                else
                    mss = await mediaStreamFacade.CreateMediaStreamSourceAsync(url, _cancellationTokenSource.Token).ConfigureAwait(false);

                if (null == mss)
                {
                    Debug.WriteLine("AudioTrackStreamer.RunStreamingAsync() unable to create media stream source");
                }
                else
                {
                    streamer.SetSource(mss);

                    await mediaStreamFacade.PlayingTask.ConfigureAwait(false);

                    return;
                }
            }
            catch (OperationCanceledException)
            {
                return;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("AudioTrackStreamer.RunStreamingAsync() failed: " + ex.ExtendedMessage());
            }

            if (null == mediaStreamFacade)
                return;

            await CleanupMediaStreamFacadeAsync(mediaStreamFacade).ConfigureAwait(false);
        }
        /// <summary>
        /// Called when the playstate changes, except for the Error state (see OnError)
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time the playstate changed</param>
        /// <param name="playState">The new playstate of the player</param>
        /// <remarks>
        /// Play State changes cannot be cancelled. They are raised even if the application
        /// caused the state change itself, assuming the application has opted-in to the callback.
        /// 
        /// Notable playstate events: 
        /// (a) TrackEnded: invoked when the player has no current track. The agent can set the next track.
        /// (b) TrackReady: an audio track has been set and it is now ready for playack.
        /// 
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            switch (playState)
            {
                case PlayState.TrackEnded:
                    if (currentPlaylist.Count > 0)
                        player.Track = GetNextTrack();
                    break;
                case PlayState.TrackReady:
                    track.BeginEdit();
                    track.Title = currentPlaylist[currentTrackNumber].Title;
                    track.EndEdit();
                    player.Play();
                    break;
                case PlayState.Shutdown:
                    // TODO: Handle the shutdown state here (e.g. save state)
                    player.Close();
                    break;
                case PlayState.Unknown:
                    break;
                case PlayState.Stopped:
                    break;
                case PlayState.Paused:
                    break;
                case PlayState.Playing:
                    break;
                case PlayState.BufferingStarted:
                    track.BeginEdit();
                        track.Title = "Buffering...";
                    track.EndEdit();
                    break;
                case PlayState.BufferingStopped:
                    track.BeginEdit();
                    track.Title = currentPlaylist[currentTrackNumber].Title;
                    track.EndEdit();
                    break;
                case PlayState.Rewinding:
                    track.BeginEdit();
                    track.Title = "Rewinding...";
                    track.EndEdit();
                    break;
                case PlayState.FastForwarding:
                    track.BeginEdit();
                    track.Title = "FastForwarding...";
                    track.EndEdit();
                    break;
            }

            NotifyComplete();
        }