Exemple #1
0
        public async void Delete(object arg)
        {
            if (!App.SettingsHelper.ConfirmDelete || ShowMessage(AppResources.DeleteSingleMessageText,
                                                                 AppResources.DeleteMessageCaption, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                //Uow.MemoTagRepository.DeleteByMemo(_memo);
                Uow.FavoriteRepository.DeleteByMemo(_memo);
                Uow.MemoRepository.Delete(_memo);
                //Uow.Save();

                TileHelper.UnPinMemo(_memo);

                if (_instance.Track != null && _instance.Track.Source.OriginalString.Contains(_memo.AudioFile))
                {
                    _instance.Close();
                }

                await StorageHelper.DeleteFileAsync(_memo.AudioFile);

                if (!string.IsNullOrWhiteSpace(_memo.ImageFile))
                {
                    await(StorageHelper.DeleteFileAsync(_memo.ImageFile));
                }

                if (NavigationService.CanGoBack)
                {
                    NavigationService.GoBack();
                }
            }
        }
        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();
        }
        /// <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();
        }
Exemple #4
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("AudioPlayer.OnUserAction() track.Source {0} track.Tag {1} action {2}",
                null == track ? "<no track>" : null == track.Source ? "<none>" : track.Source.ToString(),
                null == track ? "<no track>" : track.Tag ?? "<none>", action);

            try
            {
                switch (action)
                {
                    case UserAction.Play:
                        UpdateTrack(player);

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

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

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

                        break;
                    case UserAction.FastForward:
                        if (null != track && null != track.Source)
                            player.FastForward();

                        break;
                    case UserAction.Rewind:
                        if (null != track && null != track.Source)
                            player.Rewind();

                        break;
                    case UserAction.Seek:
                        if (null != track)
                            player.Position = (TimeSpan)param;

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

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

                        break;
                    case UserAction.SkipPrevious:
                        var previousTrack = GetPreviousTrack();
                        if (previousTrack != null)
                            player.Track = previousTrack;

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

                        break;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("AudioPlayer.OnUserAction() failed: " + ex.ExtendedMessage());

                // Is there anything we can do about this?
                try
                {
                    player.Close();
                }
                catch (Exception ex2)
                {
                    Debug.WriteLine("AudioPlayer.OnUserAction() close failed: " + ex2.ExtendedMessage());
                }
            }
            finally
            {
                NotifyComplete();
            }
        }
        /// <summary>
        /// Called when the playstate changes, except for the Error state (see OnError)
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time the playstate changed</param>
        /// <param name="playState">The new playstate of the player</param>
        /// <remarks>
        /// Play State changes cannot be cancelled. They are raised even if the application
        /// caused the state change itself, assuming the application has opted-in to the callback.
        /// 
        /// Notable playstate events: 
        /// (a) TrackEnded: invoked when the player has no current track. The agent can set the next track.
        /// (b) TrackReady: an audio track has been set and it is now ready for playack.
        /// 
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            switch (playState)
            {
                case PlayState.TrackEnded:
                    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();
        }