private static void SkipNext(BackgroundAudioPlayer player, int amount)
 {
     if (!IsLiveStream(player.Track))
     {
         Skip(player, true, amount);
     }
 }
示例#2
0
 /// <summary>
 /// </summary>
 /// <param name="player">
 /// </param>
 private void StopPlayingMix(BackgroundAudioPlayer player)
 {
     try
     {
         if (player.PlayerState != PlayState.Unknown &&
             player.PlayerState != PlayState.Stopped &&
             player.PlayerState != PlayState.Error)
         {
             player.Stop();
         }
     }
     catch (InvalidOperationException)
     {
     }
     finally
     {
         try
         {
             player.Track = null;
         }
         catch (InvalidOperationException)
         {
         }
     }
 }
示例#3
0
 public static void BroadcastTrackIfNeeded(BackgroundAudioPlayer player, List <AudioObj> playlist = null, PlaybackSettings settings = null, bool allowCache = false, bool bypassChecks = false)
 {
     try
     {
         if (!bypassChecks && (player.PlayerState != Microsoft.Phone.BackgroundAudio.PlayState.Playing || (DateTime.Now - AudioTrackHelper._lastTimeBroadcastAttempt).TotalSeconds < 3.0))
         {
             return;
         }
         AudioTrackHelper._lastTimeBroadcastAttempt = DateTime.Now;
         if (settings == null)
         {
             settings = PlaylistManager.ReadPlaybackSettings(allowCache);
             if (!settings.Broadcast)
             {
                 return;
             }
         }
         AudioTrack track = player.Track;
         if (track == null || track.GetTagId() == null)
         {
             return;
         }
         AudioTrackHelper.EnsureAppGlobalStateInitialized();
         AudioService.Instance.StatusSet("", track.GetTagId(), (Action <BackendResult <long, ResultCode> >)(res => {}));
     }
     catch (Exception ex)
     {
         Logger.Instance.Error("Broadcast track failed", ex);
     }
 }
 private static void SkipPrevious(BackgroundAudioPlayer player, int amount)
 {
     if (!IsLiveStream(player.Track))
     {
         Skip(player, false, amount);
     }
 }
示例#5
0
        /// <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
        /// </remarks>
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            switch (playState)
            {
            case PlayState.TrackReady:
                player.Play();
                break;

            case PlayState.Stopped:
                break;

            case PlayState.TrackEnded:
                this.Lifetime.Add(
                    (from _ in this.LoadNowPlayingAsync()
                     from t in this.PlayNextTrackAsync(player)
                     select t).ObserveOn(Scheduler.CurrentThread).Finally(this.Completed).Subscribe(
                        _ => { },
                        ex => this.ReportFatalStopError(ex, null)));
                return;

            case PlayState.Error:
                this.Lifetime.Add(
                    (from _ in this.LoadNowPlayingAsync()
                     from stop in this.NowPlaying.StopAsync(TimeSpan.Zero)
                     select stop).ObserveOn(Scheduler.CurrentThread).Finally(this.Completed).Subscribe(
                        _ => { },
                        ex => this.ReportFatalStopError(ex, null)));
                return;
            }

            this.Completed();
        }
示例#6
0
        /// <summary>
        /// Increments the currentTrackNumber and plays the correpsonding track.
        /// </summary>
        /// <param name="player">
        /// The BackgroundAudioPlayer
        /// </param>
        private IObservable <PortableUnit> SkipToNextTrackAsync(BackgroundAudioPlayer player)
        {
            Debug.WriteLine("Player: SkipToNextTrackAsync");

            if (!this.NowPlaying.Set.SkipAllowed)
            {
                return(Observable.Empty <PortableUnit>());
            }

            var nextTrack = from nextResponse in this.NowPlaying.SkipToNextTrackAsync(player).Do(
                response =>
            {
                this.NowPlaying.Set = response.Set;
            })
                            from _ in this.NowPlaying.SaveNowPlayingAsync().ObserveOn(Scheduler.CurrentThread)
                            from play in this.PlayTrackAsync(player)
                            select play;

            return(nextTrack.Catch <PortableUnit, WebException>(ex =>
            {
                // TODO: Do more testing on this...
                ////if (player.Track != null)
                ////{
                ////    player.Track.BeginEdit();
                ////    player.Track.PlayerControls = EnabledPlayerControls.Pause;
                ////    player.Track.EndEdit();
                ////}

                return Observable.Empty <PortableUnit>();
            }).OnErrorResumeNext(Observable.Empty <PortableUnit>()));
        }
        /// <summary>
        /// Called when the user requests an action using application/system provided UI
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time of the user action</param>
        /// <param name="action">The action the user has requested</param>
        /// <param name="param">The data associated with the requested action.
        /// In the current version this parameter is only for use with the Seek action,
        /// to indicate the requested position of an audio track</param>
        /// <remarks>
        /// User actions do not automatically make any changes in system state; the agent is responsible
        /// for carrying out the user actions if they are supported.
        ///
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            switch (action)
            {
            case UserAction.Play:
                PlayTrack(player);
                break;

            case UserAction.Pause:
                if (PlayState.Playing == player.PlayerState)
                {
                    player.Pause();
                }
                break;

            case UserAction.SkipPrevious:
                PlayPreviousTrack(player);
                break;

            case UserAction.SkipNext:
                PlayNextTrack(player);
                break;
            }

            NotifyComplete();
        }
示例#8
0
        /// <summary>
        /// Called when the user requests an action using application/system provided UI
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time of the user action</param>
        /// <param name="action">The action the user has requested</param>
        /// <param name="param">The data associated with the requested action.
        /// In the current version this parameter is only for use with the Seek action,
        /// to indicate the requested position of an audio track</param>
        /// <remarks>
        /// User actions do not automatically make any changes in system state; the agent is responsible
        /// for carrying out the user actions if they are supported.
        ///
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            switch (action)
            {
            case UserAction.Play:
                if (player.PlayerState != PlayState.Playing)
                {
                    player.Play();
                }
                break;

            case UserAction.Stop:
                player.Stop();
                break;

            case UserAction.Pause:
                player.Pause();
                break;

            default:
                break;
            }

            NotifyComplete();
        }
        /// <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:
                    player.Track = GetNextTrack();
                    break;
                case PlayState.TrackReady:
                    player.Play();
                    break;
                case PlayState.Shutdown:
                    // TODO: Handle the shutdown state here (e.g. save state)
                    break;
                case PlayState.Unknown:
                    break;
                case PlayState.Stopped:
                    _playlistHelper.SetAllTracksToNotPlayingAndSave();
                    break;
                case PlayState.Paused:
                    break;
                case PlayState.Playing:
                    break;
                case PlayState.BufferingStarted:
                    break;
                case PlayState.BufferingStopped:
                    break;
                case PlayState.Rewinding:
                    break;
                case PlayState.FastForwarding:
                    break;
            }

            NotifyComplete();
        }
示例#10
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            backgroundAudioPlayer= BackgroundAudioPlayer.Instance;
            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!storage.FileExists("Making love without nothing at all.mp3"))
                {
                    StreamResourceInfo resource = Application.GetResourceStream(new Uri("Assets/Making love without nothing at all.mp3", UriKind.Relative));
                    using (IsolatedStorageFileStream file = storage.CreateFile("Making love without nothing at all.mp3"))
                    {
                        int chunkSize = 4096;
                        byte[] bytes = new byte[chunkSize];
                        int byteCount;
                        while ((byteCount = resource.Stream.Read(bytes, 0, chunkSize)) > 0)
                        {
                            file.Write(bytes, 0, byteCount);
                        }
                    }
                }
            }

            backgroundAudioPlayer.PlayStateChanged += backgroundAudioPlayer_PlayStateChanged;


            base.OnNavigatedTo(e);
        }
        /// <summary>
        /// Called when the user requests an action using application/system provided UI
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time of the user action</param>
        /// <param name="action">The action the user has requested</param>
        /// <param name="param">The data associated with the requested action.
        /// In the current version this parameter is only for use with the Seek action,
        /// to indicate the requested position of an audio track</param>
        /// <remarks>
        /// User actions do not automatically make any changes in system state; the agent is responsible
        /// for carrying out the user actions if they are supported.
        ///
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            try
            {
                switch (action)
                {
                case UserAction.Play:
                    PlayTrack(player);
                    break;

                case UserAction.Pause:
                    player.Pause();
                    break;

                case UserAction.Stop:
                    player.Stop();
                    break;

                case UserAction.SkipPrevious:
                    PlayPreviousTrack(player);
                    break;

                case UserAction.SkipNext:
                    PlayNextTrack(player);
                    break;
                }
            }
            catch { }
            NotifyComplete();
        }
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            switch (action)
            {
                case UserAction.Play:
                    if (PlayState.Playing != player.PlayerState)
                    {
                        player.Play();
                    }
                    break;

                case UserAction.Stop:
                    player.Stop();
                    break;

                case UserAction.Pause:
                    if (PlayState.Playing == player.PlayerState)
                    {
                        player.Pause();
                    }
                    break;
                case UserAction.Rewind:
                  player.Position = player.Position.Subtract(new TimeSpan(0,0,10));
                    break;

                case UserAction.FastForward:
                  player.Position = player.Position.Add(new TimeSpan(0,0,10));
                    break;
            }

            NotifyComplete();
        }
        /// <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)
        {
            Debug.WriteLine("OnPlayStateChanged() playState " + playState);

            switch (playState)
            {
                case PlayState.TrackEnded:
                    player.Track = GetPreviousTrack();
                    break;
                case PlayState.TrackReady:
                    player.Play();
                    break;
                case PlayState.Shutdown:
                    // TODO: Handle the shutdown state here (e.g. save state)
                    break;
                case PlayState.Unknown:
                    break;
                case PlayState.Stopped:
                    break;
                case PlayState.Paused:
                    break;
                case PlayState.Playing:
                    break;
                case PlayState.BufferingStarted:
                    break;
                case PlayState.BufferingStopped:
                    break;
                case PlayState.Rewinding:
                    break;
                case PlayState.FastForwarding:
                    break;
            }

            NotifyComplete();
        }
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            ShellTile mainTile = ShellTile.ActiveTiles.FirstOrDefault();
            switch (action)
            {
                case UserAction.Play:
                    if (PlayState.Paused == player.PlayerState)
                    {
                        player.Play();

                        mainTile.Update(new StandardTileData
                        {
                            BackContent = "Play"
                        });

                    }
                    break;

                case UserAction.Pause:
                    player.Pause();

                    mainTile.Update(new StandardTileData
                    {
                        BackContent = "Pause"
                    });
                    break;
            }
            NotifyComplete();
        }
示例#15
0
        /// <summary>
        /// Called when the user requests an action using application/system provided UI
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time of the user action</param>
        /// <param name="action">The action the user has requested</param>
        /// <param name="param">The data associated with the requested action.
        /// In the current version this parameter is only for use with the Seek action,
        /// to indicate the requested position of an audio track</param>
        /// <remarks>
        /// User actions do not automatically make any changes in system state; the agent is responsible
        /// for carrying out the user actions if they are supported.
        ///
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            switch (action)
            {
            case UserAction.Play:
                PlayTrack(player);
                break;

            case UserAction.Pause:
                player.Pause();
                break;

            case UserAction.SkipPrevious:
                PlayPreviousTrack(player);
                break;

            case UserAction.SkipNext:
                PlayNextTrack(player);
                break;

            case UserAction.Seek:
                player.Position = (TimeSpan)param;
                break;
            }

            NotifyComplete();
        }
        /// <summary>
        /// Called when the user requests an action using application/system provided UI
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time of the user action</param>
        /// <param name="action">The action the user has requested</param>
        /// <param name="param">The data associated with the requested action.
        /// In the current version this parameter is only for use with the Seek action,
        /// to indicate the requested position of an audio track</param>
        /// <remarks>
        /// User actions do not automatically make any changes in system state; the agent is responsible
        /// for carrying out the user actions if they are supported.
        ///
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            switch (action)
            {
            case UserAction.Play:
                if (PlayState.Playing != player.PlayerState)
                {
                    player.Track = _playList[currentTrackNumber];
                }
                break;

            case UserAction.Stop:
                player.Stop();
                break;

            case UserAction.Pause:
                if (PlayState.Playing == player.PlayerState)
                {
                    player.Pause();
                }
                break;

            case UserAction.FastForward:
                // Fast Forward only works with non-MSS clients.
                // If the Source is null, we are streaming an MSS.
                if (track.Source != null)
                {
                    player.FastForward();
                }
                break;

            case UserAction.Rewind:
                // Rewind only works with non-MSS clients.
                // If the Source is null, we are streaming an MSS.
                if (track.Source != null)
                {
                    player.Rewind();
                }
                break;

            case UserAction.Seek:
                // Seek only works with non-MSS clients.
                // If the Source is null, we are streaming an MSS.
                if (track.Source != null)
                {
                    player.Position = (TimeSpan)param;
                }
                break;

            case UserAction.SkipNext:
                player.Track = GetNextTrack();
                break;

            case UserAction.SkipPrevious:
                player.Track = GetPreviousTrack();
                break;
            }

            NotifyComplete();
        }
示例#17
0
        /// <summary>
        /// playstate 更改时调用,但 Error 状态除外(参见 OnError)
        /// </summary>
        /// <param name="player">BackgroundAudioPlayer</param>
        /// <param name="track">在 playstate 更改时播放的曲目</param>
        /// <param name="playState">播放机的新 playstate </param>
        /// <remarks>
        /// 无法取消播放状态更改。即使应用程序
        /// 导致状态自行更改也会提出这些更改,假定应用程序已经选择了回调。
        ///
        /// 值得注意的 playstate 事件:
        /// (a) TrackEnded: 播放器没有当前曲目时激活。代理可设置下一曲目。
        /// (b) TrackReady: 音轨已设置完毕,现在可以播放。
        ///
        /// 只在代理请求完成之后调用一次 NotifyComplete(),包括异步回调。
        /// </remarks>
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            switch (playState)
            {
                case PlayState.TrackEnded:
                    //player.Track = GetPreviousTrack();
                    //player.Track = GetNextTrack();
                    PlayNextTrack(player);
                    break;
                case PlayState.TrackReady:
                    player.Play();
                    break;
                case PlayState.Shutdown:
                    // TODO: 在此处理关机状态(例如保存状态)
                    break;
                case PlayState.Unknown:
                    break;
                case PlayState.Stopped:
                    break;
                case PlayState.Paused:
                    break;
                case PlayState.Playing:
                    break;
                case PlayState.BufferingStarted:
                    break;
                case PlayState.BufferingStopped:
                    break;
                case PlayState.Rewinding:
                    break;
                case PlayState.FastForwarding:
                    break;
            }

            NotifyComplete();
        }
示例#18
0
        /// <summary>
        /// Called when the user requests an action using application/system provided UI
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time of the user action</param>
        /// <param name="action">The action the user has requested</param>
        /// <param name="param">The data associated with the requested action.
        /// In the current version this parameter is only for use with the Seek action,
        /// to indicate the requested position of an audio track</param>
        /// <remarks>
        /// User actions do not automatically make any changes in system state; the agent is responsible
        /// for carrying out the user actions if they are supported.
        ///
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            try {
                switch (action)
                {
                case UserAction.Play:
                    player.Play();
                    break;

                case UserAction.Stop:
                    player.Stop();
                    break;

                case UserAction.Pause:
                    player.Pause();
                    break;

                case UserAction.FastForward:
                    player.FastForward();
                    break;

                case UserAction.Rewind:
                    player.Rewind();
                    break;

                case UserAction.Seek:
                    try {
                        player.Position = (TimeSpan)param;
                    } catch (InvalidOperationException) {
                        // thrown occasionally. what to do?
                    }
                    break;

                case UserAction.SkipNext:
                    var maybeNext = GetNextTrack();
                    if (maybeNext != null)
                    {
                        player.Track = maybeNext;
                        // no need to play as playback is started when the track is "ready"
                        //player.Play();
                    }
                    break;

                case UserAction.SkipPrevious:
                    var maybePrevious = GetPreviousTrack();
                    if (maybePrevious != null)
                    {
                        player.Track = maybePrevious;
                        //player.Play();
                    }
                    break;
                }
            } catch (Exception) {
                // Might throw SystemException on some rare occasions?
                // TODO: reproduce, handle exception
                var tmp = 0;
            }
            NotifyComplete();
        }
 /// <summary>
 /// Called when the user requests an action using system-provided UI and the application has requesed
 /// notifications of the action
 /// </summary>
 /// <param name="player">The BackgroundAudioPlayer</param>
 /// <param name="track">The track playing at the time of the user action</param>
 /// <param name="action">The action the user has requested</param>
 /// <param name="param">The data associated with the requested action.
 /// In the current version this parameter is only for use with the Seek action,
 /// to indicate the requested position of an audio track</param>
 /// <remarks>
 /// User actions do not automatically make any changes in system state; the agent is responsible
 /// for carrying out the user actions if they are supported
 /// </remarks>
 protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
 {
     if (action == UserAction.Play)
         player.Play();
     else if (action == UserAction.Pause)
         player.Pause();
     NotifyComplete();
 }
示例#20
0
 /// <summary>
 /// Called when the user requests an action using application/system provided UI
 /// </summary>
 /// <param name="player">The BackgroundAudioPlayer</param>
 /// <param name="track">The track playing at the time of the user action</param>
 /// <param name="action">The action the user has requested</param>
 /// <param name="param">The data associated with the requested action.
 /// In the current version this parameter is only for use with the Seek action,
 /// to indicate the requested position of an audio track</param>
 /// <remarks>
 /// User actions do not automatically make any changes in system state; the agent is responsible
 /// for carrying out the user actions if they are supported.
 ///
 /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
 /// </remarks>
 protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
 {
     if (action == UserAction.Play)
     {
         player.Track = new AudioTrack(new Uri("XN.mp3", UriKind.Relative), "Duy Nguyen", "Quang Lê", "Xuân 2013", null);
         NotifyComplete();
     }
 }
示例#21
0
 private void PlayPreviousTrack(BackgroundAudioPlayer player)
 {
     if (--currentTrackNumber < 0)
     {
         currentTrackNumber = _playList.Count - 1;
     }
     PlayTrack(player);
 }
示例#22
0
 /// <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)
 {
     if (playState == PlayState.TrackReady)
     {
         player.Play();
         NotifyComplete();
     }
 }
示例#23
0
 private void PlayTrack(BackgroundAudioPlayer player)
 {
     // Play it
     if ((player.Track != null) && (player.PlayerState != PlayState.Playing))
     {
         player.Play();
     }
 }
示例#24
0
文件: AudioPlayer.cs 项目: cstfb/Luoo
 private void PlayPreviousTrack(BackgroundAudioPlayer player)
 {
     if (--currentTrackNumber < 0)
     {
         currentTrackNumber = playList.Count - 1;
     }
     player.Track = playList[currentTrackNumber];
 }
示例#25
0
文件: AudioPlayer.cs 项目: cstfb/Luoo
 private void PlayNextTrack(BackgroundAudioPlayer player)
 {
     if (++currentTrackNumber >= playList.Count)
     {
         currentTrackNumber = 0;
     }
     player.Track = playList[currentTrackNumber];
 }
示例#26
0
        /// <summary>
        /// Called when the user requests an action using application/system provided UI
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time of the user action</param>
        /// <param name="action">The action the user has requested</param>
        /// <param name="param">The data associated with the requested action.
        /// In the current version this parameter is only for use with the Seek action,
        /// to indicate the requested position of an audio track</param>
        /// <remarks>
        /// User actions do not automatically make any changes in system state; the agent is responsible
        /// for carrying out the user actions if they are supported.
        ///
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            switch (action)
            {
            case UserAction.Play:
                if (player.PlayerState == PlayState.Paused)
                {
                    PopulatePlaylist(false);
                }
                else
                {
                    PopulatePlaylist(true);
                }
                if (currentPlaylist != null && currentPlaylist.Count > 0)
                {
                    player.Track = currentPlaylist[currentTrackNumber];
                }
                break;

            case UserAction.Stop:
                currentPlaylist    = null;
                currentTrackNumber = 0;
                player.Stop();
                break;

            case UserAction.Pause:
                player.Pause();
                break;

            case UserAction.FastForward:
                player.FastForward();
                break;

            case UserAction.Rewind:
                player.Rewind();
                break;

            case UserAction.Seek:
                player.Position = (TimeSpan)param;
                break;

            case UserAction.SkipNext:
                if (currentPlaylist != null && currentPlaylist.Count > 0)
                {
                    player.Track = GetNextTrack();
                }
                break;

            case UserAction.SkipPrevious:
                if (currentPlaylist != null && currentPlaylist.Count > 0)
                {
                    player.Track = GetPreviousTrack();
                }
                break;
            }

            NotifyComplete();
        }
示例#27
0
 private void Play(BackgroundAudioPlayer player)
 {
     if (player.Track != null && player.PlayerState != PlayState.Playing)
     {
         // Workaround: According to the Dev Center, the app has crashed a
         // number of times due to a SystemException here. No idea.
         Utils.Suppress <SystemException>(player.Play);
     }
 }
示例#28
0
        private void PlayNextTrack(BackgroundAudioPlayer player)
        {
            if (++currentTrackNumber >= _playList.Count)
            {
                currentTrackNumber = 0;
            }

            PlayTrack(player);
        }
示例#29
0
        /// <summary>
        /// Decrements the currentTrackNumber and plays the correpsonding track.
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        private void PlayPreviousTrack(BackgroundAudioPlayer player)
        {
            if (--CurrentTrackNumber < 0)
            {
                CurrentTrackNumber = AudioTracks.Count - 1;
            }

            PlayTrack(player);
        }
示例#30
0
        /// <summary>
        /// Increments the currentTrackNumber and plays the correpsonding track.
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        private void PlayNextTrack(BackgroundAudioPlayer player)
        {
            if (++CurrentTrackNumber >= AudioTracks.Count)
            {
                CurrentTrackNumber = 0;
            }

            PlayTrack(player);
        }
示例#31
0
 /// <summary>
 /// </summary>
 /// <param name="player">
 /// </param>
 /// <returns>
 /// </returns>
 private IObservable <PortableUnit> StopPlayingAsync(BackgroundAudioPlayer player)
 {
     Debug.WriteLine("Player: StopPlayingAsync");
     return(this.NowPlaying.StopAsync(player)
            .Catch <PortableUnit, ServiceException>(ex => ObservableEx.SingleUnit())
            .Catch <PortableUnit, WebException>(ex => ObservableEx.SingleUnit())
            .ObserveOn(Scheduler.CurrentThread)
            .Do(_ => this.StopPlayingMix(player), ex => this.StopPlayingMix(player)));
 }
示例#32
0
        private void PlayNextTrack(BackgroundAudioPlayer player)
        {
            if (++currentTrackNumber >= _playList.Count)
            {
                currentTrackNumber = 0;
            }

            PlayTrack(player);
        }
示例#33
0
        private void PlayPreviousTrack(BackgroundAudioPlayer player)
        {
            if (--currentTrackNumber < 0)
            {
                currentTrackNumber = _playList.Count - 1;
            }

            PlayTrack(player);
        }
示例#34
0
        /// <summary>
        /// Called when the user requests an action using application/system provided UI
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time of the user action</param>
        /// <param name="action">The action the user has requested</param>
        /// <param name="param">The data associated with the requested action.
        /// In the current version this parameter is only for use with the Seek action,
        /// to indicate the requested position of an audio track</param>
        /// <remarks>
        /// User actions do not automatically make any changes in system state; the agent is responsible
        /// for carrying out the user actions if they are supported.
        ///
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected async override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            switch (action)
            {
            case UserAction.Play:
                if (player.PlayerState != PlayState.Playing)
                {
                    player.Play();
                }
                break;

            case UserAction.Stop:
                player.Stop();
                break;

            case UserAction.Pause:
                player.Pause();
                break;

            case UserAction.FastForward:
                player.FastForward();
                break;

            case UserAction.Rewind:
                player.Rewind();
                break;

            case UserAction.Seek:
                player.Position = (TimeSpan)param;
                break;

            case UserAction.SkipNext:
            {
                AudioTrack newTrack = await GetNextStation(player.Track.Artist);

                if (track != null)
                {
                    player.Track = newTrack;
                }
                break;
            }

            case UserAction.SkipPrevious:
            {
                AudioTrack newTrack = await GetPreviousStation(player.Track.Artist);

                if (track != null)
                {
                    player.Track = newTrack;
                }
                break;
            }
            }

            NotifyComplete();
        }
示例#35
0
        /// <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:
                Func <List <GuidToTrackMapping>, AudioTrack, GuidToTrackMapping> defineNextTrackPredicate = (mappings, currentTrack) =>
                {
                    var index = mappings.IndexOf(mappings.Single(o => o.Guid == new Guid(currentTrack.Tag)));
                    index++;
                    if (index >= mappings.Count)
                    {
                        // no random, no repeat !
                        return(null);
                    }
                    return(new GuidToTrackMapping {
                        Guid = mappings[index].Guid, Track = mappings[index].Track
                    });
                };
                player.Track = GetNextTrack(track, defineNextTrackPredicate);
                break;

            case PlayState.TrackReady:
                player.Play();
                break;

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

            case PlayState.Unknown:
                break;

            case PlayState.Stopped:
                break;

            case PlayState.Paused:
                break;

            case PlayState.Playing:
                break;

            case PlayState.BufferingStarted:
                break;

            case PlayState.BufferingStopped:
                break;

            case PlayState.Rewinding:
                break;

            case PlayState.FastForwarding:
                break;
            }

            NotifyComplete();
        }
 protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
 {
     switch (playState)
     {
         case PlayState.TrackReady:
             player.Play();
             break;
     }
     NotifyComplete();
 }
示例#37
0
        private void ffButtonClicked(object sender, EventArgs e)
        {
            BackgroundAudioPlayer player = BackgroundAudioPlayer.Instance;

            if (player != null && player.PlayerState == PlayState.Playing)
            {
                player.Position = (player.Position.TotalSeconds + 30 < player.Track.Duration.TotalSeconds) ? TimeSpan.FromSeconds(player.Position.TotalSeconds + 30) :
                                  TimeSpan.FromSeconds(player.Track.Duration.TotalSeconds);
            }
        }
示例#38
0
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            bool flag = true;

            try
            {
                switch (playState)
                {
                case PlayState.TrackReady:
                    if (player.PlayerState != PlayState.Playing)
                    {
                        flag = false;
                        AudioTrackHelper.PlayCurrentTrack(player, (Action <bool>)(res => this.NotifyComplete()), false);
                        break;
                    }
                    break;

                case PlayState.TrackEnded:
                    PlaybackSettings settings = PlaylistManager.ReadPlaybackSettings(false);
                    if (settings.Repeat)
                    {
                        player.Stop();
                        player.Position = TimeSpan.FromSeconds(0.0);
                        flag            = false;
                        AudioTrackHelper.PlayCurrentTrack(player, (Action <bool>)(res => this.NotifyComplete()), false);
                        break;
                    }
                    bool       startedNewCycle;
                    AudioTrack nextTrack = this.GetNextTrack(player, out startedNewCycle, settings);
                    if (nextTrack != null)
                    {
                        if (!startedNewCycle)
                        {
                            player.Track = nextTrack;
                            AudioTrackHelper.PlayCurrentTrack(player, (Action <bool>)(res => this.NotifyComplete()), false);
                            flag = false;
                            break;
                        }
                        this.NotifyComplete();
                        break;
                    }
                    break;
                }
                AudioTrackHelper.BroadcastTrackIfNeeded(player, null, null, false, false);
                if (!flag)
                {
                    return;
                }
                this.NotifyComplete();
            }
            catch
            {
                this.NotifyComplete();
            }
        }
示例#39
0
        /// <summary>
        /// Called when the user requests an action using system-provided UI and the application has requesed
        ///   notifications of the action
        /// </summary>
        /// <param name="player">
        /// The BackgroundAudioPlayer
        /// </param>
        /// <param name="track">
        /// The track playing at the time of the user action
        /// </param>
        /// <param name="action">
        /// The action the user has requested
        /// </param>
        /// <param name="param">
        /// The data associated with the requested action.
        ///   In the current version this parameter is only for use with the Seek action,
        ///   to indicate the requested position of an audio track
        /// </param>
        /// <remarks>
        /// User actions do not automatically make any changes in system state; the agent is responsible
        ///   for carrying out the user actions if they are supported
        /// </remarks>
        protected override void OnUserAction(
            BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            switch (action)
            {
            case UserAction.Stop:
                try
                {
                    if (player.PlayerState != PlayState.Paused || !PlayerService.NowPlayingExists())
                    {
                        this.Lifetime.Add((from _ in this.LoadNowPlayingAsync()
                                           from __ in this.StopPlayingAsync(player)
                                           select __).Finally(this.Completed).Subscribe(_ => { }, ex => this.ReportFatalStopError(ex, null)));
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                    // Uh oh background resources not available.
                }

                break;

            case UserAction.Pause:
                try
                {
                    player.Pause();
                }
                catch (InvalidOperationException)
                {
                    // Probably no track.. just continue on our merry way
                }

                break;

            case UserAction.Play:
                this.Lifetime.Add((from _ in this.LoadNowPlayingAsync()
                                   from __ in this.PlayTrackAsync(player)
                                   select __).ObserveOn(Scheduler.CurrentThread).Finally(this.Completed).Subscribe(_ => { },
                                                                                                                   ex => this.ReportFatalStopError(ex, null)));

                return;

            case UserAction.SkipNext:
                this.Lifetime.Add((from _ in this.LoadNowPlayingAsync()
                                   from __ in this.SkipToNextTrackAsync(player)
                                   select __).ObserveOn(Scheduler.CurrentThread).Finally(this.Completed).Subscribe(_ => { },
                                                                                                                   ex => this.ReportFatalStopError(ex, null)));

                return;
            }

            this.Completed();
        }
示例#40
0
 /// <summary>
 /// Called whenever there is an error with playback, such as an AudioTrack not downloading correctly
 /// </summary>
 /// <param name="player">The BackgroundAudioPlayer</param>
 /// <param name="track">The track that had the error</param>
 /// <param name="error">The error that occured</param>
 /// <param name="isFatal">If true, playback cannot continue and playback of the track will stop</param>
 /// <remarks>
 /// This method is not guaranteed to be called in all cases. For example, if the background agent
 /// itself has an unhandled exception, it won't get called back to handle its own errors.
 /// </remarks>
 protected override void OnError(BackgroundAudioPlayer player, AudioTrack track, Exception error, bool isFatal)
 {
     if (isFatal)
     {
         Abort();
     }
     else
     {
         NotifyComplete();
     }
 }
示例#41
0
 /// <summary>
 /// Called whenever there is an error with playback, such as an AudioTrack not downloading correctly
 /// </summary>
 /// <param name="player">The BackgroundAudioPlayer</param>
 /// <param name="track">The track that had the error</param>
 /// <param name="error">The error that occured</param>
 /// <param name="isFatal">If true, playback cannot continue and playback of the track will stop</param>
 /// <remarks>
 /// This method is not guaranteed to be called in all cases. For example, if the background agent
 /// itself has an unhandled exception, it won't get called back to handle its own errors.
 /// </remarks>
 protected override void OnError(BackgroundAudioPlayer player, AudioTrack track, Exception error, bool isFatal)
 {
     if (isFatal)
     {
         Abort();
     }
     else
     {
         NotifyComplete();
     }
 }
示例#42
0
        /// <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:
                    //player.Track = GetPreviousTrack();
                    player.Track = null;
                    break;
                case PlayState.TrackReady:
                    player.Play();
                    connectedEvent.Set();

                    if (track != null && track.Tag != null)
                    {
                        var data = track.Tag.ToString().Split('$');
                        var url = data[data.Length - 1];
                        var title = data[1];
                        var type = data[2];

                        //#region from http://stackoverflow.com/questions/7159900/detect-application-launch-from-universal-volume-control
                        //MediaHistoryItem nowPlaying = new MediaHistoryItem();
                        //nowPlaying.Title = title;
                        //nowPlaying.PlayerContext.Add("station", title);
                        //MediaHistory.Instance.NowPlaying = nowPlaying;
                        //#endregion
                    }
                    break;
                case PlayState.Shutdown:
                    // TODO: Handle the shutdown state here (e.g. save state)
                    break;
                case PlayState.Unknown:
                    break;
                case PlayState.Stopped:
                    break;
                case PlayState.Paused:
                    break;
                case PlayState.Playing:
                    break;
                case PlayState.BufferingStarted:
                    break;
                case PlayState.BufferingStopped:
                    break;
                case PlayState.Rewinding:
                    break;
                case PlayState.FastForwarding:
                    break;
            }

            NotifyComplete();
        }
示例#43
0
        /// <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.TrackReady:
                    // Wiedergabe wurde in PlayTrack() bereits festgelegt
                    player.Play();
                    break;
                case PlayState.TrackEnded:
                    PlayNextTrack(player);
                    break;
            }

            NotifyComplete();
        }
示例#44
0
        /// <summary>
        /// Called when the user requests an action using system-provided UI and the application has requesed
        /// notifications of the action
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time of the user action</param>
        /// <param name="action">The action the user has requested</param>
        /// <param name="param">The data associated with the requested action.
        /// In the current version this parameter is only for use with the Seek action,
        /// to indicate the requested position of an audio track</param>
        /// <remarks>
        /// User actions do not automatically make any changes in system state; the agent is responsible
        /// for carrying out the user actions if they are supported
        /// </remarks>
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action,
                                             object param)
        {
            switch (action)
            {
                case UserAction.Play:
                    playTrack(player);
                    break;

                case UserAction.Stop:
                    player.Stop();
                    break;
            }

            NotifyComplete();
        }
示例#45
0
        private void PlayPreviousTrack(BackgroundAudioPlayer player)
        {
            if (_playList.Count == 0)
            {
                loadPlaylist();
            }
            else if (--currentTrackNumber < 0)
            {
                currentTrackNumber = _playList.Count - 1;
                StorageUtility.writeStringToFile(IsolatedStorageFile.GetUserStoreForApplication(),
                "CurrentTrackNumber.txt",
                currentTrackNumber.ToString(CultureInfo.InvariantCulture));
            }

            player.Track = _playList[currentTrackNumber];
            player.Play();
        }
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            switch (playState)
            {
                case PlayState.TrackEnded:
                    player.Close();
                    break;

                case PlayState.TrackReady:
                    player.Volume = 1.0;
                    player.Play();
                    break;

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

                case PlayState.Unknown:
                    break;

                case PlayState.Stopped:
                    break;

                case PlayState.Paused:
                    break;

                case PlayState.Playing:
                    break;

                case PlayState.BufferingStarted:
                    break;

                case PlayState.BufferingStopped:
                    break;

                case PlayState.Rewinding:
                    break;

                case PlayState.FastForwarding:
                    break;
            }

            NotifyComplete();
        }
示例#47
0
        /// <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:
                    //player.Track = GetPreviousTrack();
                    if (currentTrack < playlist.Count - 1)
                    {
                        currentTrack += 1;
                        player.Track = playlist[currentTrack];
                    }
                    else
                    {
                        player.Track = null;
                    }
                    break;
                case PlayState.TrackReady:
                    player.Play();
                    break;
                case PlayState.Shutdown:
                    // TODO: Handle the shutdown state here (e.g. save state)
                    break;
                case PlayState.Unknown:
                    break;
                case PlayState.Stopped:
                    break;
                case PlayState.Paused:
                    break;
                case PlayState.Playing:
                    break;
                case PlayState.BufferingStarted:
                    break;
                case PlayState.BufferingStopped:
                    break;
                case PlayState.Rewinding:
                    break;
                case PlayState.FastForwarding:
                    break;
            }

            NotifyComplete();
        }
示例#48
0
        private void PlayTrack(BackgroundAudioPlayer player)
        {
            if (NetworkInterface.GetIsNetworkAvailable())
            {
                string numberString = StorageUtility.readStringFromFile(IsolatedStorageFile.GetUserStoreForApplication(),
                                                       "CurrentTrackNumber.txt");
                if (numberString != null)
                    currentTrackNumber = Int16.Parse(numberString);
                if (_playList.Count == 0)
                {
                    loadPlaylist();
                }
                else
                {
                    player.Track = _playList[currentTrackNumber];
                    player.Play();
                }

            }
        }
示例#49
0
 /// <summary>
 /// Called when the user requests an action using application/system provided UI
 /// </summary>
 /// <param name="player">The BackgroundAudioPlayer</param>
 /// <param name="track">The track playing at the time of the user action</param>
 /// <param name="action">The action the user has requested</param>
 /// <param name="param">The data associated with the requested action.
 /// In the current version this parameter is only for use with the Seek action,
 /// to indicate the requested position of an audio track</param>
 /// <remarks>
 /// User actions do not automatically make any changes in system state; the agent is responsible
 /// for carrying out the user actions if they are supported.
 /// 
 /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
 /// </remarks>
 protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
 {
     switch (action)
     {
         case UserAction.Play:
             PlayTrack(player);
             break;
         case UserAction.Pause:
             player.Pause();
             break;
         case UserAction.SkipPrevious:
             PlayPreviousTrack(player);
             break;
         case UserAction.SkipNext:
             PlayNextTrack(player);
             break;
     }
     
     NotifyComplete();
 }
示例#50
0
        /// <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
        /// </remarks>
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            switch (playState)
            {
                case PlayState.TrackReady:
                    // The track to play is set in the PlayTrack method.
                    player.Volume = 1;
                    player.Play();
                    break;

                case PlayState.TrackEnded:
                    try
                    {
                        player.Stop();
                    }
                    catch (Exception e)
                    {
                        //Console.WriteLine(e);
                    }
                    break;
            }
            NotifyComplete();
        }
        /// <summary>
        ///     Called when the user requests an action using application/system provided UI
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time of the user action</param>
        /// <param name="action">The action the user has requested</param>
        /// <param name="param">
        ///     The data associated with the requested action.
        ///     In the current version this parameter is only for use with the Seek action,
        ///     to indicate the requested position of an audio track
        /// </param>
        /// <remarks>
        ///     User actions do not automatically make any changes in system state; the agent is responsible
        ///     for carrying out the user actions if they are supported.
        ///     Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            Debug.WriteLine("OnUserAction() action " + action);

            switch (action)
            {
                case UserAction.Play:
                    var task = Task.Run((Func<Task>)RunDownload);

                    if (player.PlayerState != PlayState.Playing)
                        player.Play();

                    task.ContinueWith(t => NotifyComplete());

                    return;
                case UserAction.Stop:
                    player.Stop();
                    break;
                case UserAction.Pause:
                    player.Pause();
                    break;
                case UserAction.FastForward:
                    player.FastForward();
                    break;
                case UserAction.Rewind:
                    player.Rewind();
                    break;
                case UserAction.Seek:
                    player.Position = (TimeSpan)param;
                    break;
                case UserAction.SkipNext:
                    player.Track = GetNextTrack();
                    break;
                case UserAction.SkipPrevious:
                    var previousTrack = GetPreviousTrack();
                    if (previousTrack != null)
                        player.Track = previousTrack;
                    break;
            }

            NotifyComplete();
        }
示例#52
0
        /// <summary>
        /// Implements the logic to get the previous AudioTrack instance.
        /// </summary>
        /// <remarks>
        /// The AudioTrack URI determines the source, which can be:
        /// (a) Isolated-storage file (Relative URI, represents path in the isolated storage)
        /// (b) HTTP URL (absolute URI)
        /// (c) MediaStreamSource (null)
        /// </remarks>
        /// <returns>an instance of AudioTrack, or null if previous track is not allowed</returns>
        private void SetPreviousTrack(BackgroundAudioPlayer player)
        {
            AudioTrack track = null;
            if (Tracks != null && Tracks.Count > 0)
            {
                TrackIndex--;
                if (TrackIndex < 0)
                {
                    TrackIndex = Tracks.Count - 1;
                }
                track = Tracks[TrackIndex];
            }

            AssignTrack(track, player, this.SetPreviousTrack);
        }
示例#53
0
 private void AssignTrack(AudioTrack track, BackgroundAudioPlayer player, Action<BackgroundAudioPlayer> failureAction)
 {
     try
     {
         player.Track = track;
         ConsecutiveFileNotFoundErrorCount = 0;
     }
     catch (FileNotFoundException)
     {
         ConsecutiveFileNotFoundErrorCount++;
         if (ConsecutiveFileNotFoundErrorCount >= Tracks.Count)
         {
             throw;
         }
         else
         {
             failureAction(player);
         }
     }
 }
示例#54
0
 /// <summary>
 /// Called when the user requests an action using application/system provided UI
 /// </summary>
 /// <param name="player">The BackgroundAudioPlayer</param>
 /// <param name="track">The track playing at the time of the user action</param>
 /// <param name="action">The action the user has requested</param>
 /// <param name="param">The data associated with the requested action.
 /// In the current version this parameter is only for use with the Seek action,
 /// to indicate the requested position of an audio track</param>
 /// <remarks>
 /// User actions do not automatically make any changes in system state; the agent is responsible
 /// for carrying out the user actions if they are supported.
 /// 
 /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
 /// </remarks>
 protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
 {
     switch (action)
     {
         case UserAction.Play:
             if (player != null && player.PlayerState != PlayState.Playing)
             {
                 player.Volume = 1;
                 player.Play();
             }
             break;
         case UserAction.Stop:
             player.Stop();
             break;
         case UserAction.Pause:
             player.Pause();
             break;
         case UserAction.FastForward:
             player.FastForward();
             break;
         case UserAction.Rewind:
             player.Rewind();
             break;
         case UserAction.Seek:
             player.Position = (TimeSpan)param;
             break;
         case UserAction.SkipNext:
             SetNextTrack(player);
             break;
         case UserAction.SkipPrevious:
             SetPreviousTrack(player);
             break;
     }
     NotifyComplete();
 }
示例#55
0
        private void setTrack(BackgroundAudioPlayer player)
        {
            switch (currentPlayListNumber)
            {
                case 0:
                    if (currentTrackNumber <= _playList1.Count-1)
                    player.Track = _playList1[currentTrackNumber];
                    break;

                case 1:
                    if (currentTrackNumber <= _playList1.Count - 1)
                    player.Track = _playList2[currentTrackNumber];
                    break;
            }
        }
示例#56
0
 /// <summary>
 /// Decrements the currentTrackNumber and plays the correpsonding track.
 /// </summary>
 /// <param name="player">The BackgroundAudioPlayer</param>
 private void PlayPreviousTrack(BackgroundAudioPlayer player)
 {
     currentPlayListNumber++;
 }
示例#57
0
 /// <summary>
 /// Increments the currentTrackNumber and plays the correpsonding track.
 /// </summary>
 /// <param name="player">The BackgroundAudioPlayer</param>
 private void PlayNextTrack(BackgroundAudioPlayer player)
 {
     currentTrackNumber++;
 }
示例#58
0
        /// <summary>
        /// Called when the user requests an action using application/system provided UI
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time of the user action</param>
        /// <param name="action">The action the user has requested</param>
        /// <param name="param">The data associated with the requested action.
        /// In the current version this parameter is only for use with the Seek action,
        /// to indicate the requested position of an audio track</param>
        /// <remarks>
        /// User actions do not automatically make any changes in system state; the agent is responsible
        /// for carrying out the user actions if they are supported.
        ///
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            switch (action)
            {
                case UserAction.Play:
                    if (track != null && track.Tag != null)
                    {
                        var data = track.Tag.ToString().Split('$');
                        var url = data[data.Length - 1];

                        var type = data[2];

                        if (type.ToLower() != "shoutcast")
                        {
                            track.Source = new Uri(url);
                        }
                    }

                    //player.Track = new AudioTrack(null, "", "", "", null, track.Tag, EnabledPlayerControls.Pause);
                    if (player.SafeGetPlayerState() != PlayState.Playing)
                    {
                        player.Play();
                    }
                    break;
                case UserAction.Stop:
                    if (player.SafeGetPlayerState() == PlayState.Playing)
                        player.Stop();
                    break;
                case UserAction.Pause:
                    if (player.SafeGetPlayerState() == PlayState.Playing)
                        player.Pause();
                    break;
                case UserAction.FastForward:
                    //player.FastForward();
                    break;
                case UserAction.Rewind:
                    //player.Rewind();
                    break;
                case UserAction.Seek:
                    //player.Position = (TimeSpan)param;
                    break;
                case UserAction.SkipNext:
                    //player.Track = GetNextTrack();
                    break;
                case UserAction.SkipPrevious:
                    //AudioTrack previousTrack = GetPreviousTrack();
                    //if (previousTrack != null)
                    //{
                    //    player.Track = previousTrack;
                    //}
                    break;
            }

            NotifyComplete();
        }
示例#59
0
 /// <summary>
 /// Plays the track in our playlist at the currentTrackNumber position.
 /// </summary>
 /// <param name="player">The BackgroundAudioPlayer</param>
 private void PlayTrack(BackgroundAudioPlayer player)
 {
     setTrack(player);
     player.Play();
 }
示例#60
0
        /// <summary>
        /// Implements the logic to get the next AudioTrack instance.
        /// In a playlist, the source can be from a file, a web request, etc.
        /// </summary>
        /// <remarks>
        /// The AudioTrack URI determines the source, which can be:
        /// (a) Isolated-storage file (Relative URI, represents path in the isolated storage)
        /// (b) HTTP URL (absolute URI)
        /// (c) MediaStreamSource (null)
        /// </remarks>
        /// <returns>an instance of AudioTrack, or null if the playback is completed</returns>
        private void SetNextTrack(BackgroundAudioPlayer player)
        {
            AudioTrack track = null;

            if (Tracks != null && Tracks.Count > 0)
            {
                TrackIndex++;
                if (TrackIndex + 1 > Tracks.Count)
                {
                    TrackIndex = 0;
                }
                track = Tracks[TrackIndex];
            }

            AssignTrack(track, player, this.SetNextTrack);
        }