public void Play(IAudioMediaAsset asset) { m_StartPosition = 0; m_State = AudioPlayerState.NotReady; m_Asset = asset as AudioMediaAsset; InitPlay(0, 0); }
private void Update() { switch (PlayMode) { case AudioPlayerModeState.Single: if (audioSource.time >= CurrentAudioClip.length) { state = AudioPlayerState.Stop; OnComplete(CurrentAudioClip.name); } break; case AudioPlayerModeState.SingleLoop: break; case AudioPlayerModeState.Order: if (audioSource.time >= CurrentAudioClip.length) { OnComplete(CurrentAudioClip.name); Play(audioIndex++); } break; case AudioPlayerModeState.Random: if (audioSource.time >= CurrentAudioClip.length) { OnComplete(CurrentAudioClip.name); Play((int)UnityEngine.Random.Range(0, audioList.Count - 1)); } break; default: break; } }
public void Stop() { if (!m_State.Equals(AudioPlayerState.stopped)) { SoundBuffer.Stop(); RefreshThread.Abort(); if (m_PlayFile == true) { fs.Close(); } else { m_lArrayPosition = 0; ByteBuffer = null; } } StateChanged ob_StateChanged = new StateChanged(m_State); m_State = AudioPlayerState.stopped; TriggerStateChangedEvent(ob_StateChanged); StateChangedEvent(this, StateChanged.FromStopped); }
private void DirectSoundOutput_PlaybackStopped(object sender, StoppedEventArgs sea) { StoppedPlayerEventArgs stoppedPlayerEventArgs = null; string nextSongTyp = ""; if (_stopCause == StopCause.EofReached) { _audioPlayerState = AudioPlayerState.Stopped; if (_nextSongType == NextSongType.NextSong) { nextSongTyp = "NEXT"; } else if (_nextSongType == NextSongType.PrevSong) { nextSongTyp = "PREV"; } else { nextSongTyp = "NONE"; } _nextSongType = NextSongType.NextSong; stoppedPlayerEventArgs = new StoppedPlayerEventArgs("EOF", nextSongTyp); } else if (_stopCause == StopCause.UserTriggered) { _audioPlayerState = AudioPlayerState.Stopped; stoppedPlayerEventArgs = new StoppedPlayerEventArgs("USR", "NONE"); } //else stoppedPlayerEventArgs = new StoppedPlayerEventArgs("UNK"); StoppedPlayerNotification(new object(), stoppedPlayerEventArgs); }
private void EnsureState(AudioPlayerState state) { while (this.PlaybackState != state) { Thread.Sleep(200); } }
public void Play() { if (audioSource.isPlaying == false) { state = AudioPlayerState.Play; audioSource.Play(); } }
// JQ changed constructor to be private (singleton) private AudioPlayer() { m_PlayFile = true; m_FastPlay = false; m_State = AudioPlayerState.Stopped; ob_VuMeter = null; // JQ Calc = new CalculationFunctions(); }
private void OnAudioPlayerStateChanged(AudioPlayerState audioPlayerState) { if (AudioPlayerState != audioPlayerState) { AudioPlayerState = audioPlayerState; _eventAggregator.GetEvent <AudioPlayerStateChangedEvent>().Publish(audioPlayerState); } }
private void OnAudioPlayerStateChanged(AudioPlayerState audioPlayerState) { if (audioPlayerState != AudioPlayerState) { AudioPlayerState = audioPlayerState; AudioPlayerStateChanged(audioPlayerState); } }
//double m_dStartPosition ; // Functions public void Play(IAudioMediaAsset asset) { m_StartPosition = 0; m_State = AudioPlayerState.NotReady; m_Asset = asset as AudioMediaAsset; //VuMeter ob_VuMeter = new VuMeter () ; //ob_VuMeter.DisplayGraph () ; InitPlay(0, 0); }
private async Task SetPlaybackStateAsync(AudioPlayerState state) { var connection = this.playbackState.FirstAsync(x => x == state).ToTask(); // This is a poor man's trampoline Task.Run(() => this.playbackState.OnNext(state)); await connection; }
private async Task PushPlaylist(Playlist playlist, AudioPlayerState state) { JObject content = MobileHelper.SerializePlaylist(playlist, state, await this.library.CurrentPlaybackTime.FirstAsync(), await this.library.TotalTime.FirstAsync()); NetworkMessage message = CreatePushMessage(PushAction.UpdateCurrentPlaylist, content); await this.SendMessage(message); }
public void Resume() { if (m_State.Equals(AudioPlayerState.Paused)) { events.AudioPlayerEvents.StateChanged e = new events.AudioPlayerEvents.StateChanged(m_State); m_State = AudioPlayerState.Playing; TriggerStateChangedEvent(e); SoundBuffer.Play(0, BufferPlayFlags.Looping); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { AudioPlayerState audioPlayerState = (AudioPlayerState)value; if (audioPlayerState == AudioPlayerState.Playing) { return(true); } return(false); }
//pausing the player public void PauseSong() { if (_audioPlayerState == AudioPlayerState.Playing) { _timer.Stop(); _audioPlayerState = AudioPlayerState.Paused; _directSoundOut.Pause(); PausedPlayerNotification(new object(), new PausedPlayerEventArgs()); } }
//stopping the player public void StopSong() { if (_audioPlayerState != AudioPlayerState.Stopped) { _timer.Stop(); _stopCause = StopCause.UserTriggered; _directSoundOut.Stop(); _audioPlayerState = AudioPlayerState.Stopped; } }
public void Pause() { if (m_State.Equals(AudioPlayerState.Playing)) { SoundBuffer.Stop(); // Change the state and trigger event events.AudioPlayerEvents.StateChanged e = new events.AudioPlayerEvents.StateChanged(m_State); m_State = AudioPlayerState.Paused; TriggerStateChangedEvent(e); } }
public void Resume() { if (m_State.Equals(AudioPlayerState.paused)) { StateChanged ob_StateChanged = new StateChanged(m_State); m_State = AudioPlayerState.playing; TriggerStateChangedEvent(ob_StateChanged); StateChangedEvent(this, StateChanged.FromPaused); SoundBuffer.Play(0, BufferPlayFlags.Looping); } }
private async Task PushPlaybackState(AudioPlayerState state) { var content = JObject.FromObject(new { state }); NetworkMessage message = CreatePushMessage(PushAction.UpdatePlaybackState, content); await this.SendMessage(message); }
private void SetAudioPlayerStatus(AudioPlayerState audioPlayerState = AudioPlayerState.Closed) { if (audioPlayerState != _audioPlayerState) { _audioPlayerState = audioPlayerState; if (_audioPlayerState == AudioPlayerState.Stopped) { Finished?.Invoke(this, new EventArgs()); } AudioPlayerStateChanged?.Invoke(audioPlayerState); } }
public static Context FromJson(JObject json) { if (json == null) { return(null); } return(new Context { System = SystemState.FromJson(json.Value <JObject>("System")), AudioPlayer = AudioPlayerState.FromJson(json.Value <JObject>("AudioPlayer")) }); }
public static StateChanged From(AudioPlayerState state) { switch (state) { case AudioPlayerState.paused: return(mFromPaused); case AudioPlayerState.playing: return(mFromPlaying); case AudioPlayerState.stopped: return(mFromStopped); } return(null); // make the compiler happy }
private async Task <ResponseInfo> GetCurrentPlaylist(JToken dontCare) { Playlist playlist = this.library.CurrentPlaylist; AudioPlayerState playbackState = await this.library.PlaybackState.FirstAsync(); TimeSpan currentTime = await this.library.CurrentPlaybackTime.FirstAsync(); TimeSpan totalTime = await this.library.TotalTime.FirstAsync(); JObject content = MobileHelper.SerializePlaylist(playlist, playbackState, currentTime, totalTime); return(CreateResponse(ResponseStatus.Success, null, content)); }
public void Pause() { if (m_State.Equals(AudioPlayerState.playing)) { SoundBuffer.Stop(); // Change the state and trigger event StateChanged ob_StateChanged = new StateChanged(m_State); m_State = AudioPlayerState.paused; TriggerStateChangedEvent(ob_StateChanged); StateChangedEvent(this, StateChanged.FromPlaying); } }
public static JObject SerializePlaylist(Playlist playlist, AudioPlayerState playbackState, TimeSpan currentTime, TimeSpan totalTime) { var networkPlaylist = new NetworkPlaylist { Name = playlist.Name, CurrentIndex = playlist.CurrentSongIndex, Songs = playlist.Select(x => x.Song.ToNetworkSong(x.Guid)).ToList().AsReadOnly(), PlaybackState = (NetworkPlaybackState)Enum.ToObject(typeof(NetworkPlaybackState), (int)playbackState), CurrentTime = currentTime, TotalTime = totalTime }; return JObject.FromObject(networkPlaylist); }
public AudioPlayer ( StartedPlayingEventHandler startedPlayingNotification, PausedPlayerEventHandler pausedPlayerNotification, StoppedPlayerEventHandler stoppedPlayerNotification ) { _stopCause = StopCause.EofReached; _audioPlayerState = AudioPlayerState.Stopped; _nextSongType = NextSongType.NextSong; StartedPlayingNotification += startedPlayingNotification; PausedPlayerNotification += pausedPlayerNotification; StoppedPlayerNotification += stoppedPlayerNotification; }
public static JObject SerializePlaylist(Playlist playlist, AudioPlayerState playbackState, TimeSpan currentTime, TimeSpan totalTime) { var networkPlaylist = new NetworkPlaylist { Name = playlist.Name, CurrentIndex = playlist.CurrentSongIndex, Songs = playlist.Select(x => x.Song.ToNetworkSong(x.Guid)).ToList().AsReadOnly(), PlaybackState = (NetworkPlaybackState)Enum.ToObject(typeof(NetworkPlaybackState), (int)playbackState), CurrentTime = currentTime, TotalTime = totalTime }; return(JObject.FromObject(networkPlaylist)); }
public async Task SetState(TrackStateViewModel track, AudioPlayerState state) { await _gate.WaitAsync(); if (track == null) { return; } TrackStateViewModel item = this.First(x => x.Equals(track)); await Task.Run(() => Parallel.ForEach(this, x => x.State = AudioPlayerState.None)); item.State = state; _gate.Release(); }
private void CheckAudioQueueStatus(AudioQueueStatus?audioQueueStatus, AudioPlayerState audioPlayerState) { if (audioQueueStatus is AudioQueueStatus audioStatus) { if (audioStatus != _audioQueueStatus) { _audioQueueStatus = audioStatus; } if (_audioQueueStatus == AudioQueueStatus.Ok) { SetAudioPlayerStatus(audioPlayerState); } } }
// constructor public AudioPlayer() { if (m_ConstructorCounter == 0) { m_ConstructorCounter++; m_State = AudioPlayerState.stopped; m_PlayFile = true; m_FastPlay = false; //AssociateEvents () ; } else { throw new Exception("This class is Singleton"); } }
//starting playing the ...player public void PlaySong(AudioFile audioFile) { _timer = new Timer(100); _timer.Enabled = true; _timer.Start(); _currentFile = audioFile; if (_audioPlayerState == AudioPlayerState.Stopped) { _stopCause = StopCause.EofReached; _nextSongType = NextSongType.NextSong; _audioPlayerState = AudioPlayerState.Playing; switch (audioFile.Format.ToLower()) { case ".mp3": _waveStream = new Mp3FileReader(audioFile.Path); break; case ".wav": _waveStream = new WaveFileReader(audioFile.Path); break; case ".aiff": _waveStream = new AiffFileReader(audioFile.Path); break; default: _waveStream = new AudioFileReader(audioFile.Path); break; } _directSoundOut = new DirectSoundOut(150); _waveChannel32 = new WaveChannel32(_waveStream, 5, 0) { PadWithZeroes = false }; _directSoundOut.Init(_waveChannel32); _directSoundOut.Play(); _directSoundOut.PlaybackStopped += DirectSoundOutput_PlaybackStopped; } else if (_audioPlayerState == AudioPlayerState.Paused) { _audioPlayerState = AudioPlayerState.Playing; _directSoundOut.Play(); } StartedPlayingNotification(new object(), new StartedPlayerEventArgs()); }
private async Task SetPlaybackStateAsync(AudioPlayerState state) { var connection = this.playbackState.FirstAsync(x => x == state).ToTask(); // This is a poor man's trampoline Task.Run(() => this.playbackState.OnNext(state)); await connection; }
private async Task PushPlaylist(Playlist playlist, AudioPlayerState state) { JObject content = MobileHelper.SerializePlaylist(playlist, state, await this.library.CurrentPlaybackTime.FirstAsync(), await this.library.TotalTime.FirstAsync()); NetworkMessage message = CreatePushMessage(PushAction.UpdateCurrentPlaylist, content); await this.SendMessage(message); }
private async Task PushPlaybackState(AudioPlayerState state) { var content = JObject.FromObject(new { state }); NetworkMessage message = CreatePushMessage(PushAction.UpdatePlaybackState, content); await this.SendMessage(message); }
public StateEventArgs(AudioPlayerState oldState, AudioPlayerState newState) { this.OldState = oldState; this.NewState = newState; }
private void EnsureState(AudioPlayerState state) { while (this.PlaybackState != state) { Thread.Sleep(200); } }
public TrackStateViewModel(Track track, AudioPlayerState state) : base(track) { State = state; }