Ejemplo n.º 1
0
        public void GetAudioSamples()
        {
            AsfStream asfStream            = new AsfStream(AsfStreamType.asfAudio, testVideoFileName, 1.0, 10.0);
            AsfAudio  asfAudio             = new AsfAudio(asfStream);
            int       requestedSampleCount = 10000;

            byte[] data = asfAudio.GetSampleBytes(requestedSampleCount);
            Assert.AreEqual(requestedSampleCount, data.Length);
        }
Ejemplo n.º 2
0
        public WmvVideoStream(string filepath)
        {
            this.filepath = filepath;
            asf           = new AsfFile(filepath);
            var audioStream = new AsfStream(asf, AsfStreamType.asfAudio, 0);

            soundStream = new AsfAudio(audioStream).GetWaveStream();
            video       = new AsfImageLoader(asf);
        }
Ejemplo n.º 3
0
        public WmaMusicStream(string filepath)
        {
            this.filepath = filepath;
            var asf = new AsfFile(filepath);

            Channels        = asf.PacketConfiguration.AudioChannels;
            Samplerate      = (int)asf.PacketConfiguration.AudioSampleRate;
            LengthInSeconds = (float)asf.PacketConfiguration.Duration;
            asf.Open();
            soundStream = new AsfAudio(new AsfStream(asf, AsfStreamType.asfAudio, 0)).GetWaveStream();
            asf.Close();
        }
Ejemplo n.º 4
0
        public void IterateAudioSamples()
        {
            AsfStream asfStream            = new AsfStream(AsfStreamType.asfAudio, testVideoFileName, 1.0, 10.0);
            AsfAudio  asfAudio             = new AsfAudio(asfStream);
            int       requestedSampleCount = 10000;
            int       receivedSampleCount  = 0;

            foreach (AudioSample audioSample in asfAudio.GetSamples(requestedSampleCount))
            {
                receivedSampleCount++;
            }
            Assert.AreEqual(requestedSampleCount, receivedSampleCount);
        }
Ejemplo n.º 5
0
        public void CreatePlayableWaveMemoryStreamManual()
        {
            //WaveStreamFromFile
            using (AsfStream asfStream = new AsfStream(AsfStreamType.asfAudio, testVideoFileName, 1.0, 4.0))
                using (AsfAudio asfAudio = new AsfAudio(asfStream))
                {
                    WaveMemoryStream waveMemoryStream = asfAudio.GetWaveStream();
                    Assert.IsNotNull(waveMemoryStream);

                    //Soundplayer will throw an exception if this is not a valid Wave stream
                    SoundPlayer soundPlayer = new SoundPlayer(waveMemoryStream);
                }
        }
Ejemplo n.º 6
0
        private void WaveFormPlayButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                double timeInSeconds = (double)startTimeOffset / 1000;
                using (AsfStream asfStream = new AsfStream(AsfStreamType.asfAudio, ViewModelLocator.MainStatic.FileName, timeInSeconds))
                    using (AsfAudio asfAudio = new AsfAudio(asfStream))
                    {
                        //play a two second sample
                        byte[] data = asfAudio.GetSampleBytes(2 * (int)asfStream.Configuration.AudioSampleRate * asfStream.Configuration.AudioChannels);

                        WaveMemoryStream mwav = new WaveMemoryStream(data, (int)asfStream.Configuration.AudioSampleRate, asfStream.Configuration.AudioBitsPerSample, asfStream.Configuration.AudioChannels);
                        SoundPlayer      sp   = new SoundPlayer(mwav);
                        sp.Play();
                    }
            }
            catch (AsfStreamException) { }
        }
Ejemplo n.º 7
0
        public void ComputeWaveForm(UInt32 presentationTime)
        {
            try
            {
                double timeInSeconds = presentationTime;
                timeInSeconds /= 1000;

                float[] samples;

                using (AsfStream asfStream = new AsfStream(AsfStreamType.asfAudio, ViewModelLocator.MainStatic.FileName, timeInSeconds))
                    using (AsfAudio asfAudio = new AsfAudio(asfStream))
                    {
                        int sampleCountForTwoSeconds = (int)(2 * asfStream.Configuration.AudioSampleRate);
                        samples = asfAudio.GetSamples(sampleCountForTwoSeconds).Select(sample => sample.Left).ToArray();
                    }
                Dispatcher.BeginInvoke((Action)(() => DrawAudio(samples)));
            }
            catch (AsfStreamException) { }
        }