Exemplo n.º 1
0
 public void Play()
 {
     RequestBuffers();
     _finished = false;
     if (_seekTime != null)
     {
         _startTime = (int)(_context.currentTime * 1000 - _seekTime.Value);
         _seekTime  = null;
         _pauseTime = 0;
         _paused    = false;
     }
     else if (_paused)
     {
         _paused     = false;
         _pauseTime += (int)(_context.currentTime * 1000 - _pauseStart);
     }
     else
     {
         _startTime = (int)(_context.currentTime * 1000);
         _pauseTime = 0;
     }
     _source        = _context.createBufferSource();
     _source.buffer = _buffer;
     _source.loop   = true;
     _source.connect(_audioNode, 0, 0);
     _source.start(0);
     _audioNode.connect(_context.destination, 0, 0);
 }
Exemplo n.º 2
0
        public void Play()
        {
            dynamic ctx = _context;

            if (ctx.state == "suspended" || ctx.state == "interrupted")
            {
                ctx.resume();
            }

            // create an empty buffer source (silence)
            _buffer = _context.CreateBuffer(2, BufferSize, _context.SampleRate);

            // create a script processor node which will replace the silence with the generated audio
            _audioNode = _context.CreateScriptProcessor(BufferSize, 0, 2);
            _audioNode.OnAudioProcess = (Action <AudioProcessingEvent>)GenerateSound;

            _circularBuffer.Clear();

            RequestBuffers();
            _finished      = false;
            _source        = _context.CreateBufferSource();
            _source.Buffer = _buffer;
            _source.Loop   = true;
            _source.Connect(_audioNode, 0, 0);
            _source.Start(0);
            _audioNode.Connect(_context.Destination, 0, 0);
        }
 public void Pause()
 {
     if (_source != null)
     {
         _source.stop(0);
         _source.disconnect(0);
     }
     _source = null;
     _audioNode.disconnect(0);
 }
 public void Play()
 {
     RequestBuffers();
     _finished      = false;
     _source        = _context.createBufferSource();
     _source.buffer = _buffer;
     _source.loop   = true;
     _source.connect(_audioNode, 0, 0);
     _source.start(0);
     _audioNode.connect(_context.destination, 0, 0);
 }
Exemplo n.º 5
0
 public void Pause()
 {
     if (_source != null)
     {
         _source.stop(0);
     }
     _source     = null;
     _paused     = true;
     _pauseStart = (int)(_context.currentTime * 1000);
     _audioNode.disconnect(0);
 }
Exemplo n.º 6
0
 public void Stop()
 {
     _finished = true;
     _paused   = false;
     _seekTime = null;
     if (_source != null)
     {
         _source.stop(0);
     }
     _source = null;
     _circularBuffer.Clear();
     _audioNode.disconnect(0);
 }
 public void Pause()
 {
     if (_source != null)
     {
         _source.Stop(0);
         _source.Disconnect(0);
     }
     _source = null;
     if (_audioNode != null)
     {
         _audioNode.Disconnect(0);
     }
     _audioNode = null;
 }
        private void PlatformResume()
        {
            if (_state == SoundState.Playing)
            {
                return;
            }

            var startPos = (_state == SoundState.Paused) ? _endTime - _startTime : 0;

            _startTime = Context.currentTime - startPos;

            // Re/create source, it needs to be recreated after each stop :\
            _source        = Context.createBufferSource();
            _source.buffer = _buffer;
            _source.connect(_stereoPannerNode);

            _source.start(0, startPos);
            _state = SoundState.Playing;
        }