private void MediaElement_MediaEnded(object sender, System.Windows.RoutedEventArgs e) { _isEnded = true; _isPlaying = false; MediaElement.Pause(); PlayStateChanged?.Invoke(this, EventArgs.Empty); }
private void OnPlayStateChanged(object sender, PlayStateEventArgs e) { if (PlayStateChanged != null && e.Playing) { PlayStateChanged.Invoke(this, new EventArgs()); } }
private void RaisePlayStateChanged() { if (PlayStateChanged != null) { PlayStateChanged.Invoke(this, State); } }
private void StateChangedSignal_SignalRaised(ISignal sender, IList <object> args) { // <signal name="PlayStateChanged"> // <arg name="state" type="(sxuuuiia(ssssxsssa{ss}a{sv}v))" direction="out"/> // </signal> var state = args.First() as AllJoynMessageArgStructure; PlayStateChanged?.Invoke(this, new PlayState(state)); }
public void Stop() { MediaElement.Pause(); if (_isPlaying != false) { _isPlaying = false; PlayStateChanged?.Invoke(this, EventArgs.Empty); } }
/// <summary> /// Checks if playback state (internal player) has changed. /// If so, it updates state snapshot and invokes state change event. /// </summary> private void CheckPlayStateChange() { bool playing = _player.State == PlayerState.Playing; if (_lastPlayState != playing) { _lastPlayState = playing; PlayStateChanged?.Invoke(this, new EventArgs()); } }
private void DoTick() { _previousContext = _currentContext; try { _currentContext = _api.GetPlayback(); } catch (SpotifyWebApiException ex) { MessageBox.Show(ex.Message); Thread.Sleep(5000); return; } try { if (_currentContext == null) { return; } // Check volume change if (CompareContext(c => c.Device?.VolumePercent, out var oldVolume, out var newVolume)) { // Volume Changed VolumeChanged?.Invoke(this, new VolumeChangeEventArgs(oldVolume.GetValueOrDefault(), newVolume.GetValueOrDefault())); } if (CompareContext(c => c.Item, out var oldTrack, out var newTrack)) { // Track Changed TrackChanged?.Invoke(this, new TrackChangeEventArgs(oldTrack, newTrack)); } if (CompareContext(c => c.IsPlaying)) { // Playstate Changed PlayStateChanged?.Invoke(this, new PlayStateChangeEventArgs(_currentContext.IsPlaying)); } if (CompareContext(c => c.ProgressMs, out var oldProgressMs, out var newProgressMs)) { // Track Time Changed TrackTimeChanged?.Invoke(this, new TrackTimeChangeEventArgs(TimeSpan .FromMilliseconds(newProgressMs))); } Tick?.Invoke(this, new EventArgs()); } catch { } }
public void Play() { if (_isEnded) { MediaElement.Stop(); } MediaElement.Play(); _isEnded = false; if (_isPlaying != true) { _isPlaying = true; PlayStateChanged?.Invoke(this, EventArgs.Empty); } }
protected void CurrentStateChanged() { if (IsPlaying) { _progressHandle.Start(); } else { _progressHandle.Stop(); } OnPropertyChanged("IsPlaying"); OnPropertyChanged("CurrentState"); PlayStateChanged?.Invoke(this, EventArgs.Empty); PlaybackStateChanged?.Invoke(this, new PlayStateChangedEventArgs(CurrentState)); }
public ControlBar() { InitializeComponent(); this.Background = new SolidColorBrush(Colors.Transparent); Seekbar.TimePositionChanged += Seekbar_OnTimePositionChange; Seekbar.PositionChanged += (position) => PositionChanged?.Invoke(position); Volume.VolumeChanged += (volume) => VolumeChanged?.Invoke(volume); Play.PlayStateChanged += (play) => PlayStateChanged?.Invoke(play); Maximize.Clicked += () => MaximizeClicked?.Invoke(); Menu.AudioClicked += () => AudiosClicked?.Invoke(); Menu.SubtitlesClicked += () => SubtitlesClicked?.Invoke(); Menu.ExitClicked += () => ExitClicked?.Invoke(); Menu.ConfigClicked += () => ConfigClicked?.Invoke(); this.MouseLeave += ControlBar_MouseLeave; this.MouseEnter += ControlBar_MouseEnter; }
private void ButtonPause_Click(object sender, RoutedEventArgs e) { if (Group != null) { State = SoundPlayState.Paused; } if (PlayStateChanged != null) { PlayStateChanged.Invoke(this, State); } if (Click != null) { Click.Invoke(this, new RoutedEventArgs()); } }
private void MediaPlayerOnCurrentStateChanged(MediaPlayer sender, object args) { Logger.Info(sender.CurrentState.ToString()); DispatcherHelper.CheckBeginInvokeOnUI(() => { if (sender.CurrentState == MediaPlayerState.Playing) { _positionTimer.Start(); } else { _positionTimer.Stop(); } PlayStateChanged?.Invoke(this, EventArgs.Empty); }); }
private void Bar_PlayStateChanged(bool isplaying) { if (isplaying) { MPVInterop.Instance.MPVPlay(); Dispatcher.Invoke(() => { if (Preview.Visibility == Visibility.Visible) { Preview.Visibility = Visibility.Collapsed; } }); } else { MPVInterop.Instance.MPVPause(); } PlayStateChange(isplaying); PlayStateChanged?.Invoke(Bar.IsPlaying); }
private void Player_PlayStateChanged(object player, CustomEventArgs <MediaPluginState> args) { PlayStateChanged.IfNotNull(i => i(this, new ScriptEventArgs <string>(args.Value.ToString()))); }
/// <summary> /// 播放指定的音乐 /// </summary> /// <param name="music">如果传入null,则自动播放当前列表的第一个</param> public async Task Play(Music music = null) { if (music == null && MusicsListCollection.Count == 0) { throw new ArgumentException(); } if (this._audioPlayableServices.PlayState == PlayState.Paused) { this._audioPlayableServices.Resume(); return; } Stop(); if (MusicsListCollection.Count == 0) { MusicsListCollection.Add(music); CurrentMusic = music; } if (music == null) { CurrentMusic = MusicsListCollection[0]; } else { var tmp = MusicsListCollection.FirstOrDefault(x => x.Id == music.Id); if (tmp == null) { MusicsListCollection.Add(music); CurrentMusic = music; } else { CurrentMusic = tmp; } } var netWorkDataResult = await this._netWorkServices.GetAsync <Music>("Common", "GetMusicById", new { CurrentMusic.Id }); if (!netWorkDataResult.Successed) { this._logger.Log($"请求音乐地址失败,对应的id:{CurrentMusic.Id},名称{CurrentMusic.Name}", Category.Exception, Priority.High); return; } CurrentMusic.Url = netWorkDataResult.Data.Url; if (!string.IsNullOrEmpty(netWorkDataResult.Data.Url)) { this._audioPlayableServices.Play(netWorkDataResult.Data.Url); PlayStateChanged?.Invoke(this, this._audioPlayableServices.PlayState); } else if (PayMusicProgress(CurrentMusic)) { netWorkDataResult = await this._netWorkServices.GetAsync <Music>("Common", "GetMusicById", new { CurrentMusic.Id }); if (!netWorkDataResult.Successed) { this._logger.Log($"请求音乐地址失败,对应的id:{CurrentMusic.Id},名称{CurrentMusic.Name}", Category.Exception, Priority.High); return; } CurrentMusic.Url = netWorkDataResult.Data.Url; if (!string.IsNullOrEmpty(netWorkDataResult.Data.Url)) { this._audioPlayableServices.Play(netWorkDataResult.Data.Url); PlayStateChanged?.Invoke(this, this._audioPlayableServices.PlayState); } } }
/// <summary> /// 停止播放 /// </summary> public void Stop() { this._audioPlayableServices.Stop(); this._audioPlayableServices.Position = TimeSpan.Zero; PlayStateChanged?.Invoke(this, this._audioPlayableServices.PlayState); }
/// <summary> /// 暂停播放 /// </summary> public void Pause() { this._audioPlayableServices.Pause(); PlayStateChanged?.Invoke(this, this._audioPlayableServices.PlayState); }
protected override void OnMouseUp(MouseButtonEventArgs e) { IsPlaying = !IsPlaying; PlayStateChanged?.Invoke(IsPlaying); }
public void Play(PlayRequest p, PlayerSettings settings) { _playRequest = p; if (settings.KeyBindings == null) { settings.KeyBindings = KeyBindings.Default; } if (!string.IsNullOrEmpty(p.PreviewImageSourceUri)) { Preview.Source = new BitmapImage(new Uri(p.PreviewImageSourceUri)); Preview.Visibility = Visibility.Visible; } if (_topControl != _playControl) { MPVInterop.Instance.Initialize(VideoPlayer); _playControl = _topControl; } else { Stop(); } _settings = null; SendSettings(settings); _settings = settings; if (p.IsPlaylist) { MPVInterop.Instance.DoMpvCommand("loadlist", p.Uri); } else { MPVInterop.Instance.DoMpvCommand("loadfile", p.Uri); if (p.ExternalSubtitles != null) { foreach (var n in p.ExternalSubtitles) { MPVInterop.Instance.DoMpvCommand("sub-add", n); } } if (p.ExternalAudios != null) { foreach (var n in p.ExternalAudios) { MPVInterop.Instance.DoMpvCommand("audio-add", n); } } } StartWatcher(); if (!p.Autoplay) { MPVInterop.Instance.MPVPause(); } else { MPVInterop.Instance.MPVPlay(); } Bar.IsPlaying = p.Autoplay; PlayStateChanged?.Invoke(Bar.IsPlaying); }
private void OnPlayStateChanged(object s, PlayStateChangedEventArgs e) { PlayStateChanged?.Invoke(this, e); }
protected void playStateChanged() { PlayStateChanged?.Invoke(this, new PlayStateChangedEventArgs(currentPlayState)); }
private void HandlePlayStateMessage(bool isPlaying) { IsPlaying = isPlaying; PlayStateChanged?.Invoke(this, new PlayStateChangedEventArgs(IsPlaying)); }