Пример #1
0
        public bool StopDecoder()
        {
            try
            {
                if (_mediaCodec != null)
                {
                    _mediaCodec.Stop();
                    _mediaCodec.Release();
                }

                if (_audioTrack != null)
                {
                    _audioTrack.Stop();
                    _audioTrack.Release();
                }

                _encoderThread?.Interrupt();
                _decoderThread?.Interrupt();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #2
0
        public void Clear()
        {
            recorder?.Stop();
            recorder?.Release();
            recorder?.Dispose();
            recorder = null;

            audioTrack?.Stop();
            audioTrack?.Release();
            audioTrack?.Dispose();
            audioTrack = null;
        }
Пример #3
0
        /* //play short tone on cennection
         * private void websocketClient_Opened(object sender, EventArgs e)
         * {
         *
         *  websocketClient.Send("2000");
         *  Thread.Sleep(333);
         *  websocketClient.Send("2000");
         *
         * }
         */

        private void websocketClient_MessageReceived(object sender, MessageReceivedEventArgs e)
        {
            if (!isPlaying)
            {
                byte[] GeneratedSnd = CreateSound(int.Parse(e.Message));
                track     = new AudioTrack(Stream.Music, 8000, ChannelOut.Mono, Encoding.Pcm16bit, 80000, AudioTrackMode.Static);
                prevTone  = int.Parse(e.Message);
                isPlaying = !isPlaying;
                track.Write(GeneratedSnd, 0, 80000);

                try
                {
                    track.Play();
                }
                catch (Java.Lang.IllegalStateException)
                {
                    track.Flush();
                    track.Release();
                }
            }
            else if (isPlaying && prevTone != int.Parse(e.Message))
            {
                isPlaying = !isPlaying;
                track.Stop();
                track.Flush();
                track.Release();

                byte[] GeneratedSnd = CreateSound(int.Parse(e.Message));
                track     = new AudioTrack(Stream.Music, 8000, ChannelOut.Mono, Encoding.Pcm16bit, 80000, AudioTrackMode.Static);
                prevTone  = int.Parse(e.Message);
                isPlaying = !isPlaying;
                track.Write(GeneratedSnd, 0, 80000);

                try
                {
                    track.Play();
                }
                catch (Java.Lang.IllegalStateException)
                {
                    track.Flush();
                    track.Release();
                }
            }
            else
            {
                isPlaying = !isPlaying;
                track.Stop();
                track.Flush();
                track.Release();
            }
        }
Пример #4
0
 public void AudioPlayRelease()
 {
     record.Stop();
     audioTrack.Stop();
     audioTrack.Release();
     record.Release();
 }
Пример #5
0
        public void Stop()
        {
            lock (stateLocker)
            {
                if (recorder != null)
                {
                    if (recorder.RecordingState == RecordState.Recording)
                    {
                        recorder.Stop();
                        recorder.Release();
                        recorder        = null;
                        recordingThread = null;
                    }
                }

                if (player != null)
                {
                    if (player.PlayState == PlayState.Playing)
                    {
                        player.Stop();
                        player.Release();
                        player = null;
                    }
                }

                OnMessage?.Invoke(this, "Stopped");
            }
        }
Пример #6
0
    public void stop()
    {
        if (!running)
        {
            return;
        }

        running = false;

        MainActivity.Instance.VolumeControlStream = Stream.NotificationDefault;

        if (audioPlayer != null)
        {
            try
            {
                audioPlayer.Stop();
                audioPlayer.Release();
            }
            catch (Exception)
            {
            }

            audioPlayer.Dispose();
            audioPlayer = null;
        }

        if (audioDecoder != null)
        {
            audioDecoder.stop();
            audioDecoder.Dispose();
            audioDecoder = null;
        }

        bufferSize = 0;
    }
Пример #7
0
        void IDualityBackend.Shutdown()
        {
            // Shut down the streaming thread
            if (streamWorker != null)
            {
                streamWorkerEnd = true;
                if (!streamWorker.Join(1000))
                {
                    streamWorker.Abort();
                }
                streamWorkerQueueEvent.Dispose();
                streamWorkerEnd        = false;
                streamWorkerQueueEvent = null;
                streamWorkerQueue      = null;
                streamWorker           = null;
            }

            if (masterTrack != null)
            {
                masterTrack.Stop();
                masterTrack.Dispose();
                masterTrack = null;
            }

            if (activeInstance == this)
            {
                activeInstance = null;
            }
        }
Пример #8
0
        public async Task PlayOnce(System.IO.Stream stream)
        {
            await Task.Run(() =>
            {
                try
                {
                    int sampleRate = 16000;
                    var channel    = ChannelOut.Mono;
                    var encoding   = Android.Media.Encoding.Pcm16bit;
                    var buffSize   = AudioTrack.GetMinBufferSize(sampleRate, channel, encoding);

                    if (_playOnceAudioTrack == null)
                    {
                        _playOnceAudioTrack = new AudioTrack(Stream.Music, sampleRate, channel, encoding, buffSize, AudioTrackMode.Stream);
                    }

                    _playOnceAudioTrack.Stop();
                    _playOnceAudioTrack.Flush();

                    var buffer = new byte[stream.Length];
                    stream.Read(buffer, 0, buffer.Length);

                    _playOnceAudioTrack.Play();
                    _playOnceAudioTrack.Write(buffer, 0, buffer.Length);
                }
                catch (Exception ex)
                {
                }
            });
        }
Пример #9
0
 public void StopPlaying()
 {
     if (audioTrack != null)
     {
         audioTrack.Stop();
         audioTrack.Release();
     }
 }
Пример #10
0
 private void AudioTrackStop()
 {
     if (audioTrack != null)
     {
         audioTrack.Stop();
         audioTrack.Release();
         audioTrack = null;
     }
 }
 public void Close()
 {
     if (audioTrack != null)
     {
         audioTrack.Stop();
         audioTrack.Release();
         audioTrack.Dispose();
     }
 }
Пример #12
0
 public void StopProgressTone()
 {
     if (mProgressTone != null)
     {
         mProgressTone.Stop();
         mProgressTone.Release();
         mProgressTone = null;
     }
 }
Пример #13
0
 public void Stop()
 {
     if (Track != null)
     {
         Track.Stop();
         Track.Dispose();
         Track = null;
     }
 }
Пример #14
0
 public void Stop()
 {
     if (audioTrack != null)
     {
         audioTrack.Stop();
         audioTrack.Release();
         audioTrack = null;
     }
 }
Пример #15
0
        public static void ReturnAudioTrack(AudioTrack audioTrack)
        {
            AudioTrackData audioTrackData = null;

            for (int i = 0; i < m_audioTracks.Count; i++)
            {
                if (m_audioTracks[i].AudioTrack == audioTrack)
                {
                    audioTrackData = m_audioTracks[i];
                    break;
                }
            }
            if (!Mixer.EnableAudioTrackCaching)
            {
                if (audioTrackData != null)
                {
                    m_audioTracks.Remove(audioTrackData);
                }
                audioTrack.Pause();
                audioTrack.Release();
                return;
            }
            if (audioTrackData == null)
            {
                audioTrack.Pause();
                audioTrack.Release();
                return;
            }
            bool flag = false;

            if (m_audioTracks.Count > 16)
            {
                flag = true;
                for (int j = 0; j < m_audioTracks.Count; j++)
                {
                    if (m_audioTracks[j].BytesCount < audioTrackData.BytesCount)
                    {
                        flag = false;
                        break;
                    }
                }
            }
            if (flag)
            {
                audioTrack.Pause();
                audioTrack.Release();
                m_audioTracks.Remove(audioTrackData);
            }
            else
            {
                audioTrack.Stop();
                audioTrack.SetPlaybackHeadPosition(audioTrackData.BytesCount / audioTrackData.SoundBuffer.ChannelsCount / 2);
                audioTrackData.ReloadStaticDataTime = Time.FrameStartTime + 0.75;
            }
            LogCacheStats();
        }
Пример #16
0
 public void Stop()
 {
     if (_audioTrack == null)
     {
         return;
     }
     _audioTrack.Stop();
     _audioTrack.Release();
     _audioTrack = null;
 }
Пример #17
0
 private void StopImmediate()
 {
     if (audioTrackImmediate != null)
     {
         audioTrackImmediate.Stop();
         audioTrackImmediate.Release();
         audioTrackImmediate.Dispose();
         audioTrackImmediate = null;
     }
 }
Пример #18
0
 public void Stop()
 {
     if (playingTask != null)
     {
         quit = true;
         playingTask.Wait();
         playingTask = null;
     }
     audioTrack.Stop();
 }
 public void StopPlaying()
 {
     WvlLogger.Log(LogType.TraceAll, "StopPlaying()");
     if (audioTrack != null)
     {
         audioTrack.Stop();
         audioTrack.Release();
         audioTrack = null;
     }
 }
Пример #20
0
        public void Stop()
        {
            if (!_isPlaying)
            {
                return;
            }

            _audioTrack.Stop();
            _audioTrack = null;

            _isPlaying = false;
        }
Пример #21
0
 public void stop()
 {
     if (audioPlayer == null)
     {
         return;
     }
     audioPlayer.Stop();
     audioPlayer.Release();
     audioPlayer.Dispose();
     audioPlayer = null;
     running     = false;
 }
Пример #22
0
 public void PlaySound(int sampling_rate, byte[] pcm_data)
 {
     if (audio != null)
     {
         audio.Stop();
         audio.Release();
     }
     audio = new AudioTrack(Stream.Music, sampling_rate, ChannelOut.Mono, Encoding.Pcm16bit
                            , pcm_data.Length * sizeof(short), AudioTrackMode.Static);
     audio.Write(pcm_data, 0, pcm_data.Length);
     audio.Play();
 }
        public void PlaySound(int samplingRate, byte[] pcmData)
        {
            if (previousAudioTrack != null)
            {
                previousAudioTrack.Stop();
                previousAudioTrack.Release();
            }

            AudioTrack audioTrack = new AudioTrack(Stream.Music, samplingRate, ChannelOut.Mono, Android.Media.Encoding.Pcm16bit, pcmData.Length * sizeof(short), AudioTrackMode.Static);

            audioTrack.Write(pcmData, 0, pcmData.Length);
            audioTrack.Play();
            previousAudioTrack = audioTrack;
        }
Пример #24
0
 private void TogglePause()
 {
     if (audioTrack.IsRunning)
     {
         audioTrack.Stop();
     }
     else
     {
         if (audioTrack.CurrentTime >= audioTrack.Length)
         {
             audioTrack.Seek(0); // Reset
         }
         audioTrack.Start();
     }
 }
Пример #25
0
        void playSound(int freq, int duration)
        {
            var        sampleRate   = 8000;
            var        generatedSnd = genTone(sampleRate, freq, (duration * sampleRate) / 1000);
            AudioTrack audioTrack   = new AudioTrack(Stream.Music,
                                                     sampleRate, ChannelConfiguration.Mono, Encoding.Pcm16bit, generatedSnd.Length, AudioTrackMode.Stream);

            audioTrack.Play();
            audioTrack.Write(generatedSnd, 0, generatedSnd.Length);
            while (audioTrack.PlayState == PlayState.Playing)
            {
                Thread.Sleep(10);
            }
            audioTrack.Stop();
        }
Пример #26
0
        /// <summary>
        /// Stop the audio
        /// </summary>
        public static void Stop()
        {
            if (active)
            {
                Pause();

                if (song.IsPlaying)
                {
                    song.Stop();
                }

                song.Dispose();
                song = null;

                Reset();
            }
        }
Пример #27
0
 public void Stop()
 {
     if (State == SoundStates.Stopped)
     {
         return;
     }
     if (instance == null)
     {
         return;
     }
     instance.Stop();
     instance.Release();
     instance.Dispose();
     instance = null;
     audio.removeinstance();
     State = SoundStates.Stopped;
 }
Пример #28
0
    public void stop()
    {
        running = false;

        lock (pendingFrames)
        {
            pendingFrames.Clear();
            availableBuffers.Clear();
        }

        if (audioPlayer != null)
        {
            try
            {
                audioPlayer.Stop();
                audioPlayer.Release();
            }
            catch (Exception)
            {
            }

            audioPlayer.Dispose();
            audioPlayer = null;
        }

        if (audioDecoder != null)
        {
            try
            {
                audioDecoder.Stop();
                audioDecoder.Release();
            }
            catch (Exception)
            {
            }
            audioDecoder.Dispose();
            audioDecoder = null;
        }

        bufferSize = 0;
    }
Пример #29
0
        private void OnPlayButton(string koe, int speed)
        {
            var wav = new AquesTalk().synthe(koe, speed);

            if (wav.Length == 1)
            {
                return;
            }

            if (_audioTrack != null)
            {
                _audioTrack.Stop();
                _audioTrack.Release();
                _audioTrack.Dispose();
            }

            _audioTrack =
                new AudioTrack(Stream.Music, 8000, ChannelOut.Mono, Encoding.Pcm16bit, wav.Length - 44,
                               AudioTrackMode.Static);

            _audioTrack.Write(wav, 44, wav.Length - 44);
            _audioTrack.Play();
        }
Пример #30
0
            private void OnPeriodFinished()
            {
                int audioDataBufferSize;
                SoundEffectInstance instance;

                lock (this)
                {
                    ++BuffersToWrite;
                    if (BuffersToWrite == NumberOfSubBuffersInAudioTrack)
                    {
                        Track.Stop();
                    }

                    instance = CurrentInstance;
                    if (instance == null)
                    {
                        return;
                    }

                    instance.readBufferPosition += bufferSize;
                    audioDataBufferSize          = instance.soundEffect.WaveDataSize;

                    while (instance.readBufferPosition >= audioDataBufferSize && instance.IsLooped && !instance.exitLoopRequested)
                    {
                        instance.readBufferPosition -= audioDataBufferSize;
                    }

                    if (instance.readBufferPosition < audioDataBufferSize && !ShouldStop)
                    {
                        WriteNextAudioBufferToTrack();
                    }
                }
                if ((instance.readBufferPosition >= audioDataBufferSize || ShouldStop) && instance.PlayState != SoundPlayState.Paused)
                {
                    instance.Stop();
                }
            }