Example #1
0
        public override async Task <ISoundPlayerBuilder <IStorageFileEx> > BuildAsync()
        {
            if (Input == null)
            {
                return(this);
            }

            DisposeInternally();

            IRandomAccessStreamEx streamOpenFile = await Input.OpenReadAsync();

            using (Stream nativeStream = streamOpenFile.AsStreamForRead())
            {
                using (var soundStream = new SoundStream(nativeStream))
                {
                    Description = Input.Name;

                    WaveFormat = soundStream.Format;

                    _dataStream = soundStream.ToDataStream();

                    SourceVoice = VoicePool.GetVoice(WaveFormat);

                    SourceVoice.PlayWith(_dataStream);
                }
            }

            return(this);
        }
Example #2
0
        private void DisposeInternally()
        {
            Stop();

            if (SourceVoice != null)
            {
                SourceVoice.Clear();

                VoicePool.PutVoice(SourceVoice, WaveFormat);
                SourceVoice = null;
            }

            if (_dataStream != null)
            {
                _dataStream.Dispose();
                _dataStream = null;
            }
        }
Example #3
0
        private void DisposeInternally()
        {
            Stop();

            if (SourceVoice != null)
            {
                SourceVoice.Clear();
                VoicePool.PutVoice(SourceVoice, WaveFormat);
            }

            if (_overLapDataStream != null)
            {
                _overLapDataStream.Dispose();
            }

            if (_overlapSourceVoice != null)
            {
                _overlapSourceVoice.Clear();
                VoicePool.PutVoice(_overlapSourceVoice, WaveFormat);
            }
        }
Example #4
0
        public override Task <ISoundPlayerBuilder <IStorageFileEx> > BuildAsync()
        {
            DisposeInternally();

            _dataStream        = new DataStream(_currentSampleBuffer.Length, true, true);
            _overLapDataStream = new DataStream(_currentSampleBuffer.Length, true, true);

            _dataStream.Read(_currentSampleBuffer, 0, _currentSampleBuffer.Length);
            _dataStream.Seek(0, 0);

            _overLapDataStream.Read(_currentSampleBuffer, 0, _currentSampleBuffer.Length);
            _overLapDataStream.Seek(0, 0);

            SourceVoice         = VoicePool.GetVoice(WaveFormat);
            _overlapSourceVoice = VoicePool.GetVoice(WaveFormat);

            SourceVoice.PlayWith(_dataStream);
            _overlapSourceVoice.PlayWith(_overLapDataStream);

            return(Task.FromResult <ISoundPlayerBuilder <IStorageFileEx> >(this));
        }