Exemplo n.º 1
0
 public void Play(IAudioMediaAsset asset)
 {
     m_StartPosition = 0;
     m_State         = AudioPlayerState.NotReady;
     m_Asset         = asset as AudioMediaAsset;
     InitPlay(0, 0);
 }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 private void EnsureState(AudioPlayerState state)
 {
     while (this.PlaybackState != state)
     {
         Thread.Sleep(200);
     }
 }
Exemplo n.º 6
0
 public void Play()
 {
     if (audioSource.isPlaying == false)
     {
         state = AudioPlayerState.Play;
         audioSource.Play();
     }
 }
Exemplo n.º 7
0
 // 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();
 }
Exemplo n.º 8
0
 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);
     }
 }
Exemplo n.º 10
0
//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);
        }
Exemplo n.º 11
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;
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
 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);
        }
Exemplo n.º 15
0
 //pausing the player
 public void PauseSong()
 {
     if (_audioPlayerState == AudioPlayerState.Playing)
     {
         _timer.Stop();
         _audioPlayerState = AudioPlayerState.Paused;
         _directSoundOut.Pause();
         PausedPlayerNotification(new object(), new PausedPlayerEventArgs());
     }
 }
Exemplo n.º 16
0
 //stopping the player
 public void StopSong()
 {
     if (_audioPlayerState != AudioPlayerState.Stopped)
     {
         _timer.Stop();
         _stopCause = StopCause.UserTriggered;
         _directSoundOut.Stop();
         _audioPlayerState = AudioPlayerState.Stopped;
     }
 }
Exemplo n.º 17
0
 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);
     }
 }
Exemplo n.º 18
0
 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);
     }
 }
Exemplo n.º 19
0
        private async Task PushPlaybackState(AudioPlayerState state)
        {
            var content = JObject.FromObject(new
            {
                state
            });

            NetworkMessage message = CreatePushMessage(PushAction.UpdatePlaybackState, content);

            await this.SendMessage(message);
        }
Exemplo n.º 20
0
 private void SetAudioPlayerStatus(AudioPlayerState audioPlayerState = AudioPlayerState.Closed)
 {
     if (audioPlayerState != _audioPlayerState)
     {
         _audioPlayerState = audioPlayerState;
         if (_audioPlayerState == AudioPlayerState.Stopped)
         {
             Finished?.Invoke(this, new EventArgs());
         }
         AudioPlayerStateChanged?.Invoke(audioPlayerState);
     }
 }
Exemplo n.º 21
0
        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"))
            });
        }
Exemplo n.º 22
0
        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
        }
Exemplo n.º 23
0
        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));
        }
Exemplo n.º 24
0
        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);
            }
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
 public AudioPlayer
 (
     StartedPlayingEventHandler startedPlayingNotification,
     PausedPlayerEventHandler pausedPlayerNotification,
     StoppedPlayerEventHandler stoppedPlayerNotification
 )
 {
     _stopCause                  = StopCause.EofReached;
     _audioPlayerState           = AudioPlayerState.Stopped;
     _nextSongType               = NextSongType.NextSong;
     StartedPlayingNotification += startedPlayingNotification;
     PausedPlayerNotification   += pausedPlayerNotification;
     StoppedPlayerNotification  += stoppedPlayerNotification;
 }
Exemplo n.º 27
0
        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));
        }
Exemplo n.º 28
0
        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();
        }
Exemplo n.º 29
0
        private void CheckAudioQueueStatus(AudioQueueStatus?audioQueueStatus, AudioPlayerState audioPlayerState)
        {
            if (audioQueueStatus is AudioQueueStatus audioStatus)
            {
                if (audioStatus != _audioQueueStatus)
                {
                    _audioQueueStatus = audioStatus;
                }

                if (_audioQueueStatus == AudioQueueStatus.Ok)
                {
                    SetAudioPlayerStatus(audioPlayerState);
                }
            }
        }
Exemplo n.º 30
0
        // 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");
            }
        }
Exemplo n.º 31
0
        //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());
        }
Exemplo n.º 32
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;
        }
Exemplo n.º 33
0
        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);
        }
Exemplo n.º 34
0
        private async Task PushPlaybackState(AudioPlayerState state)
        {
            var content = JObject.FromObject(new
            {
                state
            });

            NetworkMessage message = CreatePushMessage(PushAction.UpdatePlaybackState, content);

            await this.SendMessage(message);
        }
Exemplo n.º 35
0
 public StateEventArgs(AudioPlayerState oldState, AudioPlayerState newState)
 {
     this.OldState = oldState;
     this.NewState = newState;
 }
Exemplo n.º 36
0
 private void EnsureState(AudioPlayerState state)
 {
     while (this.PlaybackState != state)
     {
         Thread.Sleep(200);
     }
 }
Exemplo n.º 37
0
 public TrackStateViewModel(Track track, AudioPlayerState state) : base(track)
 {
     State = state;
 }