Exemplo n.º 1
0
        private async void AudioEntry_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            await __ProgressSemaphore.WaitAsync();

            try
            {
                if (!(sender is AudioEntry))
                {
                    return;
                }

                var audioModel = (sender as AudioEntry).DataContext as AudioModel;
                if (audioModel == null)
                {
                    return;
                }

                if (__CurrentActive == null)
                {
                    Interlocked.Exchange(ref __CurrentActive, audioModel);
                }
                else
                {
                    if (__CurrentActive != audioModel)
                    {
                        switch (__CurrentActive.AudioState)
                        {
                        case PlayingState.NotInit:
                            break;

                        case PlayingState.Stopped:
                            break;

                        case PlayingState.Paused:
                        case PlayingState.Playing:
                            __CurrentActive.Stop();
                            __CurrentActive = audioModel;
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                    else
                    {
                        switch (audioModel.AudioState)
                        {
                        case PlayingState.NotInit:
                        case PlayingState.Stopped:
                            __CurrentActive = null;
                            break;
                        }
                    }
                }

                audioModel.AudioEntryClicked();
            }
            finally
            {
                __ProgressSemaphore.Release();
            }
        }
Exemplo n.º 2
0
        private async void AudioEntry_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            await __ProgressSemaphore.WaitAsync();
            try
            {
                if (!(sender is AudioEntry))
                    return;

                var audioModel = (sender as AudioEntry).DataContext as AudioModel;
                if (audioModel == null)
                    return;

                if (__CurrentActive == null)
                {
                    Interlocked.Exchange(ref __CurrentActive, audioModel);
                }
                else
                {
                    if (__CurrentActive != audioModel)
                    {
                        switch (__CurrentActive.AudioState)
                        {
                            case PlayingState.NotInit:
                                break;
                            case PlayingState.Stopped:
                                break;
                            case PlayingState.Paused:
                            case PlayingState.Playing:
                                __CurrentActive.Stop();
                                __CurrentActive = audioModel;
                                break;
                            default:
                                throw new ArgumentOutOfRangeException();
                        }
                    }
                    else
                    {
                        switch (audioModel.AudioState)
                        {
                            case PlayingState.NotInit:
                            case PlayingState.Stopped:
                                __CurrentActive = null;
                                break;
                        }
                    }
                }

                audioModel.AudioEntryClicked();
            }
            finally
            {
                __ProgressSemaphore.Release();
            }
        }