コード例 #1
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:
                    player.Play();
                    break;

                case PlayState.TrackEnded:
                    player.Position = TimeSpan.Zero;
                    player.Play();
                    break;
            } NotifyComplete();
        }
コード例 #2
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:
                player.Play();
                break;

            case PlayState.TrackEnded:
                player.Position = TimeSpan.Zero;
                player.Play();
                break;
            }
            NotifyComplete();
        }
コード例 #3
0
ファイル: AudioPlayer.cs プロジェクト: vicalloy/lb.ting
        /// <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();
        }
コード例 #4
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 = 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();
        }
コード例 #5
0
        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();
        }
コード例 #6
0
ファイル: AudioPlayer.cs プロジェクト: FlatlinerDOA/FlatBeats
        /// <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();
        }
コード例 #7
0
        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();
        }
コード例 #8
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)
        {
            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();
        }
コード例 #9
0
ファイル: AudioPlayer.cs プロジェクト: v2nek/hydra
        /// <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();
        }
コード例 #10
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();
        }
コード例 #11
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)
 {
     if (action == UserAction.Play)
         player.Play();
     else if (action == UserAction.Pause)
         player.Pause();
     NotifyComplete();
 }
コード例 #12
0
 private void PlayTrack(BackgroundAudioPlayer player)
 {
     // Play it
     if ((player.Track != null) && (player.PlayerState != PlayState.Playing))
     {
         player.Play();
     }
 }
コード例 #13
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();
     }
 }
コード例 #14
0
ファイル: AudioPlayer.cs プロジェクト: salfab/open-syno
        /// <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();
        }
コード例 #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 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();
        }
コード例 #16
0
        public void PlayPause(object arg)
        {
            if (_memo != null)
            {
                if (App.SettingsHelper.UseSystemPlayer)
                {
                    MediaPlayerLauncher playerLauncher = new MediaPlayerLauncher();

                    playerLauncher.Controls = MediaPlaybackControls.FastForward |
                                              MediaPlaybackControls.Rewind | MediaPlaybackControls.Pause | MediaPlaybackControls.Stop;

                    playerLauncher.Location    = MediaLocationType.Data;
                    playerLauncher.Media       = new Uri(_memo.AudioFile, UriKind.RelativeOrAbsolute);
                    playerLauncher.Orientation = MediaPlayerOrientation.Portrait;

                    if (!_memo.IsPlayed)
                    {
                        _memo.IsPlayed = true;
                        //Uow.Save();
                    }

                    playerLauncher.Show();
                }
                else
                {
                    if (_instance.Track == null)
                    {
                        SetAudioTrack(_memo.AudioFile, _memo.Title);
                    }

                    if (!_instance.Track.Source.OriginalString.Contains(_memo.AudioFile))
                    {
                        SetAudioTrack(_memo.AudioFile, _memo.Title);
                    }

                    if (_instance.PlayerState != PlayState.Playing)
                    {
                        _instance.Play();

                        if (!_memo.IsPlayed)
                        {
                            _memo.IsPlayed = true;
                            Uow.MemoRepository.Update(_memo);
                            //Uow.Save();
                        }
                    }
                    else
                    {
                        if (_instance.CanPause)
                        {
                            _instance.Pause();
                        }
                    }
                }
            }
        }
コード例 #17
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 = GetNextTrack();
                player.Play();
                break;

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

            case PlayState.Shutdown:
                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 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 async void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            await ConfigureThePlayer();

            switch (playState)
            {
            case PlayState.TrackEnded:
                _logger.Info("PlayStateChanged.TrackEnded");
                player.Track = await GetNextTrack();
                await InformOfPlayingTrack();

                break;

            case PlayState.TrackReady:
                _logger.Info("PlayStateChanged.TrackReady");
                try
                {
                    player.Play();
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("OnPlayStateChanged.TrackReady", ex);
                }
                NotifyComplete();
                break;

            case PlayState.Shutdown:
                await InformOfStoppedTrack();

                break;

            case PlayState.Unknown:
                _logger.Info("PlayStateChanged.Unknown");
                NotifyComplete();
                break;

            case PlayState.Stopped:
                _logger.Info("PlayStateChanged.Stopped");
                NotifyComplete();
                //_playlistHelper.SetAllTracksToNotPlayingAndSave();
                break;

            case PlayState.Paused:
                _logger.Info("PlayStateChanged.Paused");
                await _playlistHelper.SetAllTracksToNotPlayingAndSave();
                await InformOfStoppedTrack();

                break;

            default:
                NotifyComplete();
                break;
            }
        }
コード例 #19
0
        /// <summary>
        /// Plays the track in our playlist at the currentTrackNumber position.
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        private void PlayTrack(BackgroundAudioPlayer player)
        {
            if (PlayState.Paused == player.PlayerState)
            {
                // If we're paused, we already have
                // the track set, so just resume playing.
                player.Play();
            }
            else
            {
                // Set which track to play. When the TrackReady state is received
                // in the OnPlayStateChanged handler, call player.Play().
                //player.Track = _playList[currentTrackNumber];

                if (player.Track != null)
                {
                    player.Play();
                }
            }
        }
コード例 #20
0
        /// <summary>
        /// 在用户使用应用程序/系统提供的用户界面请求操作时调用
        /// </summary>
        /// <param name="player">BackgroundAudioPlayer</param>
        /// <param name="track">用户操作期间播放的曲目</param>
        /// <param name="action">用户请求的操作</param>
        /// <param name="param">与请求的操作相关联的数据。
        /// 在当前版本中,此参数仅适合与 Seek 操作一起使用,
        /// 以指明请求的乐曲的位置</param>
        /// <remarks>
        /// 用户操作不自动对系统状态进行任何更改;如果用户操作受支持,
        /// 以便执行用户操作(如果这些操作受支持)。
        ///
        /// 只在代理请求完成之后调用 NotifyComplete() 一次,包括异步回调。
        /// </remarks>
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            switch (action)
            {
            case UserAction.Play:
                if (player.PlayerState != PlayState.Playing)
                {
                    if (player.PlayerState != PlayState.Paused)
                    {
                        player.Track = track;
                    }
                    else
                    {
                        player.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:
                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();
        }
コード例 #21
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)
        {
            System.Diagnostics.Debug.WriteLine("playState is" + playState);
            switch (playState)
            {
            case PlayState.TrackReady:
                // The track to play is set in the PlayTrack method.
                player.Play();
                break;
            }

            NotifyComplete();
        }
コード例 #22
0
 private void PlayTrack(BackgroundAudioPlayer player)
 {
     if ((player.Track == null) || (player.Track.Source != _playList[currentTrackNumber].Source))
     {
         // If it's a new track, set the track
         player.Track = _playList[currentTrackNumber];
     }
     // Play it
     if ((player.Track != null) && (player.PlayerState != PlayState.Playing))
     {
         player.Play();
         ghifile(); // khi no play 1 bai hat thi no luu lai
     }
 }
コード例 #23
0
ファイル: AudioPlayer.cs プロジェクト: Amrykid/Hanasu
        /// <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();
        }
コード例 #24
0
        private void PlayTrack(BackgroundAudioPlayer player)
        {
            if ((player.Track == null) || (player.Track.Title != _playList[currentTrackNumber].Title))
            {
                // If it's a new track, set the track
                player.Track = _playList[currentTrackNumber];
            }

            // Play it
            if ((player.Track != null) && (player.PlayerState != PlayState.Playing))
            {
                player.Play();
            }
        }
コード例 #25
0
ファイル: AudioPlayer.cs プロジェクト: cstfb/Luoo
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            switch (playState)
            {
            case PlayState.TrackEnded:
                PlayNextTrack(player);
                break;

            case PlayState.TrackReady:
                player.Play();
                break;
            }
            NotifyComplete();
        }
コード例 #26
0
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            switch (action)
            {
            case UserAction.FastForward:
                player.FastForward();
                break;

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

            case UserAction.Play:
                if (player.PlayerState == PlayState.Paused)
                {
                    player.Play();
                }
                else
                {
                    Play(player);
                }
                break;

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

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

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

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

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

            default:
                break;
            }

            NotifyComplete();
        }
コード例 #27
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();
        }
コード例 #28
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();
        }
コード例 #29
0
ファイル: AudioPlayer.cs プロジェクト: Vykt0r/Music-Player
        /// <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.TrackEnded:
                    PlayNext(player);
                    break;
                case PlayState.TrackReady:
                    player.Play();
                    break;
                default:
                    break;
            }

            NotifyComplete();
        }
コード例 #30
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)
        {
            try
            {
                switch (playState)
                {
                case PlayState.TrackEnded:
                    PlayNextTrack(player);
                    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;
                }
            }
            catch { }

            NotifyComplete();
        }
コード例 #31
0
ファイル: AudioPlayer.cs プロジェクト: klfzlyt/wp7douban
        /// <summary>
        /// 在用户使用应用程序/系统提供的用户界面请求操作时调用
        /// </summary>
        /// <param name="player">BackgroundAudioPlayer</param>
        /// <param name="track">用户操作期间播放的曲目</param>
        /// <param name="action">用户请求的操作</param>
        /// <param name="param">与请求的操作相关联的数据。
        /// 在当前版本中,此参数仅适合与 Seek 操作一起使用,
        /// 以指明请求的乐曲的位置</param>
        /// <remarks>
        /// 用户操作不自动对系统状态进行任何更改;如果用户操作受支持,
        /// 以便执行用户操作(如果这些操作受支持)。
        ///
        /// 只在代理请求完成之后调用 NotifyComplete() 一次,包括异步回调。
        /// </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();
                }
                NotifyComplete();
                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:
                GetNextAudioTrack getnextaudiotrack = new NetGetNextAudioTrack(null);
                getnextaudiotrack.HaveNextTrack += (s, e) =>
                {
                    BackgroundAudioPlayer.Instance.Track = e.Track;        //应该不用加Play()

                    NotifyComplete();
                };
                getnextaudiotrack.ChangeNextTrack();
                break;

            case UserAction.SkipPrevious:
                break;
            }
        }
コード例 #32
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:
                //PlayNextTrack(player);
                player.Stop();
                break;

            case PlayState.TrackReady:
                // The track to play is set in the PlayTrack method.
                player.Play();
                break;
            }

            NotifyComplete();
        }
コード例 #33
0
ファイル: AudioPlayer.cs プロジェクト: lonkly/StereomoodWP7
        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();
        }
コード例 #34
0
ファイル: AudioPlayer.cs プロジェクト: malliina/musicpimp-win
        /// <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:
                PlayNext(player);
                break;

            case PlayState.TrackReady:
                // without this, playback may be resumed from the position of the previous track
                player.Position = TimeSpan.FromSeconds(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();
        }
コード例 #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)
        {
            System.Diagnostics.Debug.WriteLine("AGENT PLAY STATE CHANGED: " + playState.ToString());
            switch (playState)
            {
            case PlayState.TrackEnded:
                player.Track = GetNextTrack();
                break;

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

            case PlayState.Shutdown:
                SaveTrackAndTime(player, track);
                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();
        }
コード例 #36
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 = 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();
        }
コード例 #37
0
        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();
        }
コード例 #38
0
ファイル: AudioPlayer.cs プロジェクト: bNick/WPOnLinePlayer
        /// <summary>
        /// Вызывается при изменении состояния воспроизведения, за исключением состояния ошибки (см. OnError)
        /// </summary>
        /// <param name="player">BackgroundAudioPlayer</param>
        /// <param name="track">Дорожка, воспроизводимая во время изменения состояния воспроизведения</param>
        /// <param name="playState">Новое состояние воспроизведения проигрывателя</param>
        /// <remarks>
        /// Изменения состояния воспроизведения невозможно отменить. Они вызываются, даже если изменение состояния
        /// было вызвано самим приложением при условии, что в приложении используется обратный вызов.
        ///
        /// Важные события playstate:
        /// (а) TrackEnded: вызывается, когда в проигрывателе нет текущей дорожки. Агент может задать следующую дорожку.
        /// (б) TrackReady: звуковая дорожка задана и готова для воспроизведения.
        ///
        /// Вызовите NotifyComplete() только один раз после завершения запроса агента, включая асинхронные обратные вызовы.
        /// </remarks>
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            switch (playState)
            {
            case PlayState.TrackEnded:
                player.Track = GetPreviousTrack();
                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();
        }
コード例 #39
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>
        /// <para>
        /// 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.
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// <para>
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </para>
        /// </remarks>
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            System.Diagnostics.Debug.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + ":  OnPlayStateChanged() - {0}", playState);
            switch (playState)
            {
            case PlayState.TrackEnded:
                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();
        }
コード例 #40
0
ファイル: AudioPlayer.cs プロジェクト: dinesh2043/Audiobook
        /// <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();
        }
コード例 #41
0
ファイル: AudioPlayer.cs プロジェクト: lonkly/StereomoodWP7
        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();
                }

            }
        }
コード例 #42
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;

            case UserAction.SkipNext:
                SkipNext(player, 200);
                break;

            case UserAction.SkipPrevious:
                SkipPrevious(player, 200);
                break;

            case UserAction.FastForward:
                SkipNext(player, 1000);
                break;

            case UserAction.Rewind:
                SkipPrevious(player, 1000);
                break;
            }

            NotifyComplete();
        }
コード例 #43
0
ファイル: AudioPlayer.cs プロジェクト: woodgate/MegastrazWP7
        /// <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();
        }
コード例 #44
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)
        {
            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();
        }
コード例 #45
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:
                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();
        }
コード例 #46
0
ファイル: AudioPlayer.cs プロジェクト: dinesh2043/Audiobook
        /// <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)
                    //{
                        // to get audio track
                        //player.Track = this.audioTrack;
                        //player.Play();
                    //}
                    if (player.Track == null)
                    {
                        currentTrack = 0;
                        player.Track = playlist[currentTrack];
                    }
                    else
                    {
                        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:
                    //player.Track = GetNextTrack();
                    if (currentTrack < playlist.Count - 1)
                    {
                        currentTrack += 1;
                        player.Track = playlist[currentTrack];
                    }
                    else
                    {
                        player.Track = null;
                    }
                    break;
                case UserAction.SkipPrevious:
                    //AudioTrack previousTrack = GetPreviousTrack();
                    //if (previousTrack != null)
                    //{
                        //player.Track = previousTrack;
                    //}
                    break;
            }

            NotifyComplete();
        }
コード例 #47
0
ファイル: AudioPlayer.cs プロジェクト: NickCulbertson/beem
        /// <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();
        }
コード例 #48
0
ファイル: AudioPlayer.cs プロジェクト: rlecole/SaveAndPlay
 /// <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();
 }
コード例 #49
0
        private void PlayTrack(BackgroundAudioPlayer player)
        {
            /*if ((player.Track == null) || (player.Track.Title != _playList[currentTrackNumber].Title))
            {
                // If it's a new track, set the track
                //player.Track = _playList[currentTrackNumber];
            }*/

            // Play it
            if ((player.Track != null) && (player.PlayerState != PlayState.Playing))
            {
                player.Play();
            }
        }
コード例 #50
0
ファイル: AudioPlayer.cs プロジェクト: vladk1/Kaizen
        /// <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:
                    PlayNextTrack(player);
                    break;

                case PlayState.TrackReady:
                    // The track to play is set in the PlayTrack method.
                    player.Play();
                    break;
            }

            NotifyComplete();
        }
コード例 #51
0
ファイル: AudioPlayer.cs プロジェクト: vladk1/Kaizen
 /// <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();
 }
コード例 #52
0
ファイル: AudioPlayer.cs プロジェクト: kypeli/Podcatcher
        /// <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:
                    PlaylistItem currentPlaylistItem = getCurrentlyPlayingTrack();
                    if (currentPlaylistItem != null)
                    {
                        currentPlaylistItem.SavedPlayPosTick = currentPlaylistItem.TotalPlayTicks; // We hit TrackEnded event so we can save the playpos to the end.
                        // But really, this is a bug in WP8 since the player doesn't know the playpos at this point anymore.
                        updateToDBPlaylistItem(currentPlaylistItem);
                    }

                    // Start playing next track if we have one.
                    AudioTrack nextTrack = getNextPlaylistTrack();
                    if (nextTrack != null)
                    {
                        player.Track = nextTrack;
                        player.Play();
                    }
                    else
                    {
                        player.Stop();
                    }
                    break;
                case PlayState.TrackReady:
                    break;
                case PlayState.Shutdown:
                    updatePlayposForCurrentEpisode(player);
                    break;
                case PlayState.Unknown:
                    updatePlayposForCurrentEpisode(player);
                    Debug.WriteLine("Play state: Unkown");
                    break;
                case PlayState.Stopped:
                    updatePlayposForCurrentEpisode(player);
                    clearPrimaryTile();
                    Debug.WriteLine("Play state: Stopped");
                    break;
                case PlayState.Paused:
                    updatePlayposForCurrentEpisode(player);
                    Debug.WriteLine("Play state: Paused");
                    break;
                case PlayState.Playing:
                    PlaylistItem plItem = getCurrentlyPlayingTrack();
                    if (plItem != null)
                    {
                        plItem.TotalPlayTicks = player.Track.Duration.Ticks;
                        updateToDBPlaylistItem(plItem);

                        Debug.WriteLine("Play state: Playing");
                    }
                    else
                    {
                        Debug.WriteLine("Playlist item NULL!");
                    }

                    updatePlayposForCurrentEpisode(player);
                    setCurrentlyPlayingTrack(player.Track.Title);
                    break;
                case PlayState.BufferingStarted:
                    break;
                case PlayState.BufferingStopped:
                    break;
                case PlayState.Rewinding:
                    break;
                case PlayState.FastForwarding:
                    break;
            }

            NotifyComplete();
        }
コード例 #53
0
ファイル: AudioPlayer.cs プロジェクト: FlatlinerDOA/FlatBeats
        /// <summary>
        /// </summary>
        /// <param name="player">
        /// </param>
        private IObservable <PortableUnit> PlayTrackAsync(BackgroundAudioPlayer player)
        {
            if (this.UserSettings.PlayOverWifiOnly && NetworkInterface.NetworkInterfaceType != NetworkInterfaceType.Wireless80211)
            {
                return(this.StopPlayingAsync(player));
            }

            if (this.NowPlaying == null || this.NowPlaying.Set == null)
            {
                Debug.WriteLine("Player: PlayTrackAsync (Now Playing not set)");

                // Reset as we don't know what we're playing anymore.
                return(this.StopPlayingAsync(player));
            }

            try
            {
                if (player.PlayerState == PlayState.Paused && player.Track.Tag.StartsWith(this.NowPlaying.MixId + "|"))
                {
                    Debug.WriteLine("Player: PlayTrackAsync (Resume from Paused)");

                    // If we're paused, we already have
                    // the track set, so just resume playing.
                    player.Volume = 1;
                    player.Play();

                    return(ObservableEx.SingleUnit());
                }
            }
            catch (InvalidOperationException)
            {
                // Background audio resources not available
                return(ObservableEx.SingleUnit());
            }

            if (this.NowPlaying.Set.Track == null || this.NowPlaying.Set.Track.TrackUrl == null)
            {
                return(this.StopPlayingAsync(player));
            }

            Debug.WriteLine("Player: PlayTrackAsync (Playing)");

            // Set which track to play. When the TrackReady state is received
            // in the OnPlayStateChanged handler, call player.Play().
            return(from trackAddress in PlayerService.GetTrackAddressAsync(this.NowPlaying.Set.Track).ObserveOn(Scheduler.CurrentThread).Do(
                       trackUrl =>
            {
                var coverUrl = this.NowPlaying.Cover.ThumbnailUrl;
                var playControls = !this.NowPlaying.Set.IsLastTrack && this.NowPlaying.Set.SkipAllowed
                                               ? EnabledPlayerControls.Pause | EnabledPlayerControls.SkipNext
                                   | EnabledPlayerControls.FastForward
                                               : EnabledPlayerControls.Pause;
                var track = new AudioTrack(
                    trackUrl,
                    this.NowPlaying.Set.Track.Name,
                    this.NowPlaying.Set.Track.Artist,
                    this.NowPlaying.MixName,
                    coverUrl,
                    this.NowPlaying.MixId + "|" + this.NowPlaying.Set.Track.Id,
                    playControls);
                player.Track = track;
                player.Volume = 1;
            })
                   select ObservableEx.Unit);
        }
コード例 #54
0
ファイル: AudioPlayer.cs プロジェクト: kypeli/Podcatcher
        /// <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:
                    try
                    {
                        if (player.PlayerState != PlayState.Playing)
                        {
                            Debug.WriteLine("User.Action: Play");
                            player.Play();
                        }
                    }
                    catch (InvalidOperationException e)
                    {
                        Debug.WriteLine("Exception: " + e.Message);
                    }
                    catch (SystemException syse)
                    {
                        Debug.WriteLine("Exception: " + syse.Message);
                    }
                    break;
                case UserAction.Stop:
                    try
                    {
                        if (player.PlayerState != PlayState.Stopped) {
                            updatePlayposForCurrentEpisode(player);
                            player.Stop();
                            Debug.WriteLine("User.Action: Stop");
                        }
                    }
                    catch (Exception e)
                    {
                       Debug.WriteLine("Exception: " + e.Message);
                    }
                    break;

                case UserAction.Pause:
                    Debug.WriteLine("User.Action: Pause");
                    try
                    {
                        if (player.PlayerState == PlayState.Playing)
                        {
                            updatePlayposForCurrentEpisode(player);
                            player.Pause();
                        }
                    }
                    catch (InvalidOperationException e)
                    {
                        Debug.WriteLine("Exception: " + e.Message);
                    }
                    break;

                case UserAction.Seek:
                    try
                    {
                        if (player.PlayerState == PlayState.Playing)
                        {
                            player.Position = (TimeSpan)param;
                        }
                    }
                    catch (InvalidOperationException e)
                    {
                        Debug.WriteLine("Exception: " + e.Message);
                    }
                    break;

                case UserAction.SkipNext:
                    Debug.WriteLine("Skip next.");
                    updatePlayposForCurrentEpisode(player);
                    AudioTrack nextTrack = getNextPlaylistTrack();

                    if (nextTrack == null)
                    {
                        player.Position = (player.Position.TotalSeconds + 30 < player.Track.Duration.TotalSeconds) ? TimeSpan.FromSeconds(player.Position.TotalSeconds + 30) :
                                                                                                                     TimeSpan.FromSeconds(player.Track.Duration.TotalSeconds);
                    }
                    else
                    {
                        player.Track = nextTrack;
                        player.Play();
                    }
                    break;

                case UserAction.FastForward:
                    try
                    {
                        Debug.WriteLine("Player fast forward. New position: " + player.Position);
                        player.Position = (player.Position.TotalSeconds + 30 < player.Track.Duration.TotalSeconds) ? TimeSpan.FromSeconds(player.Position.TotalSeconds + 30) :
                                                                                                                     TimeSpan.FromSeconds(player.Track.Duration.TotalSeconds);

                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("Error seeking. Probably seeked passed the end.");
                    }
                    break;

                case UserAction.SkipPrevious:
                case UserAction.Rewind:
                    try
                    {
                        player.Position = (player.Position.TotalSeconds - 30 >= 0) ? TimeSpan.FromSeconds(player.Position.TotalSeconds - 30) :
                                                                                     TimeSpan.FromSeconds(0);
                        Debug.WriteLine("Player fast forward. New position: " + player.Position);
                    } catch(Exception) {
                        Debug.WriteLine("Error seeking. Probably seeked passed the start.");
                    }
                    break;
            }

            NotifyComplete();
        }
コード例 #55
0
ファイル: AudioPlayer.cs プロジェクト: mikejan/EntacikGorc
 /// <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:
             var audioInfo = (from audio in db.AudioPlaylist
                              select audio).FirstOrDefault();
             string audioUrl = audioInfo.AudioUrl;
             string audioTitle = audioInfo.AudioTitle;
             string audioArtist = audioInfo.AudioArtist;
             string audioId = audioInfo.Aid;
             player.Track = new AudioTrack(new Uri(audioUrl), audioTitle, audioArtist, null, null, audioId, EnabledPlayerControls.All);
             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:
             player.Track = GetNextTrack();
             break;
         case UserAction.SkipPrevious:
             AudioTrack previousTrack = GetPreviousTrack();
             if (previousTrack != null)
             {
                 player.Track = previousTrack;
             }
             break;
     }
     NotifyComplete();
 }
コード例 #56
0
ファイル: AudioPlayer.cs プロジェクト: Amrykid/Hanasu
        /// <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();
        }
コード例 #57
0
        /// <summary>
        /// Plays the track in our playlist at the currentTrackNumber position.
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// 
        private void PlayTrack(BackgroundAudioPlayer player)
        {
            if (PlayState.Paused == player.PlayerState)
            {
                // If we're paused, we already have 
                // the track set, so just resume playing.
                player.Play();
            }
            else
            {
                 // What's the current track?
        
                // Set which track to play. When the TrackReady state is received 
                // in the OnPlayStateChanged handler, call player.Play().
                // loadfile();
                player.Track = _playList[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 (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:
                ////    player.Track = GetNextTrack();
                //    break;
                //case UserAction.SkipPrevious:
                //    AudioTrack previousTrack = GetPreviousTrack();
                //    if (previousTrack != null)
                //    {
                //        player.Track = previousTrack;
                //    }
                //    break;
            }

            NotifyComplete();
        }
コード例 #59
0
ファイル: AudioPlayer.cs プロジェクト: aluetjen/Podcatcher
        /// <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:
                    break;
                case UserAction.Pause:
                    player.Pause();
                    break;
                case UserAction.FastForward:
                    player.Position = TimeSpan.FromSeconds(player.Position.TotalSeconds + 10);
                    Debug.WriteLine("Player fast forward. New position: " + player.Position);
                    break;
                case UserAction.Rewind:
                    player.Position = TimeSpan.FromSeconds(player.Position.TotalSeconds - 10);
                    Debug.WriteLine("Player rewind. New position: " + player.Position);
                    break;
                case UserAction.Seek:
                    player.Position = (TimeSpan)param;
                    break;
            }

            NotifyComplete();
        }
コード例 #60
0
ファイル: AudioPlayer.cs プロジェクト: rick-li/midi-browser
        /// <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)
        {
            System.Diagnostics.Debug.WriteLine("playState is" + playState);
            switch (playState)
            {

                case PlayState.TrackReady:
                    // The track to play is set in the PlayTrack method.
                    player.Play();
                    break;
            }

            NotifyComplete();
        }