Beispiel #1
0
 public void CheckState()
 {
     if (audioSource == null || (!audioSource.isPlaying && playState != AudioPlayState.Pause))
     {
         playState = AudioPlayState.Stop;
     }
 }
 protected void PlayMusicControl(AudioAsset au, string audioName, bool isLoop = true, float volumeScale = 1, float delay = 0f, float fadeTime = 0.5f)
 {
     if (au.assetName == audioName)
     {
         if (au.PlayState != AudioPlayState.Playing)
         {
             au.SetPlayState(AudioPlayState.Playing);
             AddFade(au, VolumeFadeType.FadeIn, fadeTime, delay, null, null);
             au.Play();
         }
     }
     else
     {
         AudioPlayState state = au.PlayState;
         au.SetPlayState(AudioPlayState.Playing);
         if (state == AudioPlayState.Playing)
         {
             AddFade(au, VolumeFadeType.FadeOut2In, fadeTime, delay, null, (value) =>
             {
                 PlayClip(value, audioName, isLoop, volumeScale, delay);
             });
         }
         else
         {
             PlayClip(au, audioName, isLoop, volumeScale, delay);
             AddFade(au, VolumeFadeType.FadeIn, fadeTime, delay, null, null);
         }
     }
 }
    public void Stop()
    {
        if (audioSource)
        {
            audioSource.Stop();
        }
        playState = AudioPlayState.Stop;

        if (sourceType == AudioSourceType.Music)
        {
            if (!isCallPreStop)
            {
                isCallPreStop = true;
                if (AudioPlayManager.OnMusicPreStopCallBack != null)
                {
                    AudioPlayManager.OnMusicPreStopCallBack(AssetName, musicChannel, flag);
                }
            }

            if (AudioPlayManager.OnMusicStopCallBack != null)
            {
                AudioPlayManager.OnMusicStopCallBack(AssetName, musicChannel, flag);
            }
        }
        else
        {
            if (AudioPlayManager.OnSFXStopCallBack != null)
            {
                AudioPlayManager.OnSFXStopCallBack(AssetName, flag);
            }
        }
    }
Beispiel #4
0
 public void Play()
 {
     if (currentState == AudioPlayState.Playing)
     {
         return;
     }
     if (currentState == AudioPlayState.Stopped)
     {
         finished     = false;
         currentState = AudioPlayState.Playing;
         for (int i = 0; i < bufferIds.Length; i++)
         {
             int length = BufferNeeded(this, buffer);
             AL.BufferData(bufferIds [i], bufferFormat, buffer, length, sampleRate);
             AudioDevice.CheckALError();
             AL.SourceQueueBuffer(sourceId, bufferIds [i]);
             AudioDevice.CheckALError();
             AL.SourcePlay(sourceId);
             AudioDevice.CheckALError();
         }
         device.Add(this);
         threadRunning = true;
     }
     currentState = AudioPlayState.Playing;
 }
Beispiel #5
0
 public void Play(float delay = 0f)
 {
     if (audioSource != null && audioSource.clip != null)
     {
         audioSource.PlayDelayed(delay);
         playState = AudioPlayState.Playing;
     }
 }
Beispiel #6
0
 public void Pause()
 {
     if (audioSource != null && audioSource.clip != null && audioSource.isPlaying)
     {
         audioSource.Pause();
         playState = AudioPlayState.Pause;
     }
 }
Beispiel #7
0
 public void Stop()
 {
     if (audioSource)
     {
         audioSource.Stop();
     }
     playState = AudioPlayState.Stop;
 }
 public void Play(float delay = 0f)
 {
     if (audioSource != null && audioSource.clip != null)
     {
         isCallPreStop    = false;
         audioSource.time = 0;
         audioSource.PlayDelayed(delay);
         playState = AudioPlayState.Playing;
     }
 }
Beispiel #9
0
 /// <summary>
 /// Start to play voice audio file
 /// </summary>
 public void Start()
 {
     if (player.State == PlayerState.Ready || player.State == PlayerState.Paused)
     {
         // Player's state will be "Playing"
         player.Start();
         if (player.State == PlayerState.Playing)
         {
             _state = StateConvert(player.State);
             MessagingCenter.Send <IAudioPlayService, AudioPlayState>(this, MessageKeys.PlayerStateChanged, StateConvert(player.State));
         }
     }
 }
Beispiel #10
0
        /// <summary>
        /// Pause to play audio file
        /// </summary>
        public void Pause()
        {
            if (player.State == PlayerState.Playing)
            {
                // Player's state will be "Paused"
                player.Pause();
                if (player.State == PlayerState.Paused)
                {
                    _state = StateConvert(player.State);
                    MessagingCenter.Send <IAudioPlayService, AudioPlayState>(this, MessageKeys.PlayerStateChanged, StateConvert(player.State));
                }

                Console.WriteLine(" AudioPlayService.Pause() : ", (player.State != PlayerState.Paused) ? "Failed to Pause()" : "Successfully finish to Pause()");
            }
        }
Beispiel #11
0
 public void Stop()
 {
     if (currentState == AudioPlayState.Stopped)
     {
         return;
     }
     userStopped  = true;
     currentState = AudioPlayState.Stopped;
     while (threadRunning)
     {
         ;
     }
     AL.SourceStop(sourceId);
     device.Remove(this);
     Empty();
 }
Beispiel #12
0
 public void Play(float delay = 0f)
 {
     if (audioSource != null && audioSource.clip != null)
     {
         isCallPreStop = false;
         if (playState == AudioPlayState.Pause)
         {
             audioSource.time = m_pauseTime;
         }
         else
         {
             audioSource.time = 0;
         }
         audioSource.PlayDelayed(delay);
         playState = AudioPlayState.Playing;
     }
 }
Beispiel #13
0
 /// <summary>
 /// If you want to leave PlaybackPage, you need to
 /// </summary>
 public void Stop()
 {
     if (player.State == PlayerState.Playing || player.State == PlayerState.Paused)
     {
         // Player's state will be "Ready"
         player.Stop();
         if (player.State == PlayerState.Ready)
         {
             _state = StateConvert(player.State);
             MessagingCenter.Send <IAudioPlayService, AudioPlayState>(this, MessageKeys.PlayerStateChanged, StateConvert(player.State));
         }
     }
     // Player's state will be "Idle"
     player.Unprepare();
     if (player.State == PlayerState.Idle)
     {
         _state = StateConvert(player.State);
         MessagingCenter.Send <IAudioPlayService, AudioPlayState>(this, MessageKeys.PlayerStateChanged, StateConvert(player.State));
     }
 }
Beispiel #14
0
 public void SetPlayState(AudioPlayState state)
 {
     playState = state;
 }
Beispiel #15
0
        internal void Update()
        {
            //manage state
            if (currentState == AudioPlayState.Stopped)
            {
                AL.SourceStop(sourceId);
                device.Remove(this);
                threadRunning = false;
                if (!userStopped)
                {
                    if (PlaybackFinished != null)
                    {
                        PlaybackFinished(this, true);
                    }
                }
                userStopped = false;
                return;
            }
            var state = AL.GetSourceState(sourceId);

            AudioDevice.CheckALError();
            if (currentState == AudioPlayState.Paused)
            {
                if (state != ALSourceState.Paused)
                {
                    AL.SourcePause(sourceId);
                }
                return;
            }

            //load buffers
            int processed_count;

            AL.GetSource(sourceId, ALGetSourcei.BuffersProcessed, out processed_count);
            while (processed_count > 0)
            {
                int bid = AL.SourceUnqueueBuffer(sourceId);
                if (bid != 0 && !finished)
                {
                    int length = BufferNeeded(this, buffer);
                    finished = length <= 0;
                    if (!finished)
                    {
                        AL.BufferData(bid, bufferFormat, buffer, length, sampleRate);
                        AL.SourceQueueBuffer(sourceId, bid);
                    }
                }
                --processed_count;
            }
            //check buffer
            if (state == ALSourceState.Stopped && !finished)
            {
                AL.SourcePlay(sourceId);
            }
            //are we finished?
            if (finished && state == ALSourceState.Stopped)
            {
                device.Remove(this);
                currentState  = AudioPlayState.Stopped;
                threadRunning = false;
                Empty();
                if (PlaybackFinished != null)
                {
                    PlaybackFinished(this, false);
                }
            }
        }
Beispiel #16
0
 public void Stop()
 {
     if (currentState == AudioPlayState.Stopped)
         return;
     userStopped = true;
     currentState = AudioPlayState.Stopped;
     while (threadRunning)
         ;
     AL.SourceStop (sourceId);
     device.Remove (this);
     Empty ();
 }
Beispiel #17
0
        internal void Update()
        {
            //manage state
            if (currentState == AudioPlayState.Stopped) {
                AL.SourceStop (sourceId);
                device.Remove (this);
                threadRunning = false;
                if (!userStopped) {
                    if (PlaybackFinished != null)
                        PlaybackFinished (this, true);
                }
                userStopped = false;
                return;
            }
            var state = AL.GetSourceState (sourceId);
            AudioDevice.CheckALError ();
            if (currentState == AudioPlayState.Paused) {
                if (state != ALSourceState.Paused)
                    AL.SourcePause (sourceId);
                return;
            }

            //load buffers
            int processed_count;
            AL.GetSource (sourceId, ALGetSourcei.BuffersProcessed, out processed_count);
            while (processed_count > 0) {
                int bid = AL.SourceUnqueueBuffer (sourceId);
                if (bid != 0 && !finished) {
                    int length = BufferNeeded (this, buffer);
                    finished = length <= 0;
                    if (!finished) {
                        AL.BufferData (bid, bufferFormat, buffer, length, sampleRate);
                        AL.SourceQueueBuffer (sourceId, bid);
                    }
                }
                --processed_count;
            }
            //check buffer
            if (state == ALSourceState.Stopped && !finished)
                AL.SourcePlay (sourceId);
            //are we finished?
            if (finished && state == ALSourceState.Stopped) {
                device.Remove (this);
                currentState = AudioPlayState.Stopped;
                threadRunning = false;
                Empty ();
                if(PlaybackFinished != null)
                    PlaybackFinished (this, false);
            }
        }
Beispiel #18
0
 public void Pause()
 {
     currentState = AudioPlayState.Paused;
 }
Beispiel #19
0
 public void Pause()
 {
     currentState = AudioPlayState.Paused;
 }
Beispiel #20
0
 public void SetPlaying()
 {
     playState = AudioPlayState.Playing;
 }
Beispiel #21
0
 public void Play()
 {
     if (currentState == AudioPlayState.Playing)
         return;
     if (currentState == AudioPlayState.Stopped) {
         finished = false;
         currentState = AudioPlayState.Playing;
         for (int i = 0; i < bufferIds.Length; i++) {
             int length = BufferNeeded (this, buffer);
             AL.BufferData (bufferIds [i], bufferFormat, buffer, length, sampleRate);
             AudioDevice.CheckALError ();
             AL.SourceQueueBuffer (sourceId, bufferIds [i]);
             AudioDevice.CheckALError ();
             AL.SourcePlay (sourceId);
             AudioDevice.CheckALError ();
         }
         device.Add (this);
         threadRunning = true;
     }
     currentState = AudioPlayState.Playing;
 }