private void Awake() { _material = GetComponentInChildren <Renderer>().material; _light = GetComponentInChildren <Light>(); _tonePlayer = GetComponentInChildren <TonePlayer>(); _input = GetComponent <ButtonInput>(); }
/// <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 TonePlayer.StartAsync(ToneType.Default, _audioStreamPolicy, Duration * _secUnit, _cts.Token); } catch (TaskCanceledException) { Tizen.Log.Info("TonePlayer", "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); }