Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class
        /// </summary>
        /// <param name="navigation">
        /// Navigation instance
        /// </param>
        public MainViewModel(INavigation navigation)
        {
            Navigation = navigation;

            PlayCommand = new Command(async() =>
            {
                _isPlaying         = true;
                _cts               = new CancellationTokenSource();
                _audioStreamPolicy = new AudioStreamPolicy(AudioStreamType.Media);

                PlayCommand.ChangeCanExecute();
                CancelCommand.ChangeCanExecute();

                try
                {
                    await WavPlayer.StartAsync(ResourcePath.GetPath("test.wav"), _audioStreamPolicy, _cts.Token);
                }
                catch (TaskCanceledException)
                {
                    Tizen.Log.Info("WavPlayer", "A task for playing media was canceled.");
                }
                finally
                {
                    _isPlaying = false;
                    _cts?.Dispose();
                    _audioStreamPolicy?.Dispose();
                }

                PlayCommand.ChangeCanExecute();
                CancelCommand.ChangeCanExecute();
            }, CanPlay);

            CancelCommand = new Command(() =>
            {
                if (_isPlaying)
                {
                    _cts?.Cancel();
                    _isPlaying = false;
                }

                PlayCommand.ChangeCanExecute();
                CancelCommand.ChangeCanExecute();
            }, CanCancel);
        }
 void Panic()
 {
     VIBRATEMOTOR();
     WavPlayer.StartAsync(ResourcePath.GetPath("your_temperature_is_high.wav"), new AudioStreamPolicy(AudioStreamType.Alarm));
 }