Пример #1
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);
		}
Пример #2
0
		public void Rewind()
		{
			Dispose();
			asf = new AsfFile(filepath);
			var audioStream = new AsfStream(asf, AsfStreamType.asfAudio, 0);
			soundStream = new AsfAudio(audioStream).GetWaveStream();
			video = new AsfImageLoader(asf);
		}
Пример #3
0
		public AsfImageLoader(AsfFile file)
		{
			stream = new AsfStream(file, AsfStreamType.asfImage, 0);
			WMUtils.WMCreateSyncReader(IntPtr.Zero, Rights.Playback, out syncReader);
			syncReader.OpenStream(new AsfIStream(stream));
			syncReader.SetReadStreamSamples((short)stream.Configuration.AsfVideoStreamId, false);
			Width = stream.Configuration.ImageWidth;
			Height = stream.Configuration.ImageHeight;
		}
Пример #4
0
        public AsfImage(AsfStream asfStream)
        {
            if (asfStream.StreamType != AsfStreamType.asfImage)
                throw new ArgumentException();

            _asfStream = asfStream;
            _asfMemoryStream = null;
            _sampleBitmap = null;
        }
Пример #5
0
 public void CreateImageManual()
 {
     using(AsfStream asfStream = new AsfStream(AsfStreamType.asfImage, testVideoFileName, 1.0))
     using (AsfImage asfImage = new AsfImage(asfStream))
     {
         Bitmap bitmap = asfImage.GetImage();
         Assert.AreNotEqual(bitmap, null);
     }
 }
Пример #6
0
        public AsfImage(AsfStream asfStream)
        {
            if (asfStream.StreamType != AsfStreamType.asfImage)
            {
                throw new ArgumentException();
            }

            _asfStream       = asfStream;
            _asfMemoryStream = null;
            _sampleBitmap    = null;
        }
Пример #7
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);
            }
        }
Пример #8
0
 void CreateImage(double timeInSeconds)
 {
     try
     {
         using(AsfStream asfStream = new AsfStream(_asfFile, AsfStreamType.asfImage, timeInSeconds))
         using(AsfImage asfImage = new AsfImage(asfStream))
         _bitmap = asfImage.GetImage();
     }
     catch (Exception)
     {
         _bitmap = null;
     }
     _resetEvent.Set(); // signal that worker is done
 }
Пример #9
0
        public void ValidateAsfStreamLength()
        {
            AsfStream asfStream = new AsfStream(AsfStreamType.asfStream, testVideoFileName, 1.0, 2.0);
            int bytesRead = 0;
            int totalBytesRead = 0;

            byte[] data = new byte[8192];

            do
            {
                bytesRead = asfStream.Read(data, 0, data.Length);
                totalBytesRead += bytesRead;
            } while(bytesRead > 0);

            Assert.AreEqual(asfStream.Length, totalBytesRead);
        }
Пример #10
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) { }
        }
Пример #11
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) { }
        }
Пример #12
0
		public void Dispose()
		{
			if (syncReader != null)
				Marshal.FinalReleaseComObject(syncReader);
			syncReader = null;
			if (stream != null)
				stream.Dispose();
			stream = null;
		}
Пример #13
0
 public static Bitmap FromFile(string fileName, double offset)
 {
     using (AsfStream asfStream = new AsfStream(AsfStreamType.asfImage, fileName, offset))
     using (AsfImage asfImage = new AsfImage(asfStream))
         return asfImage.GetImage();
 }
Пример #14
0
 public AsfAudio(AsfStream asfStream)
 {
     _asfStream = asfStream;
     _asfMemoryStream = null;
     _sampleBuffer = new Queue<AudioSample>();
 }
Пример #15
0
 public AsfAudio(AsfStream asfStream)
 {
     _asfStream       = asfStream;
     _asfMemoryStream = null;
     _sampleBuffer    = new Queue <AudioSample>();
 }
Пример #16
0
 public void CreateImageAsfStream()
 {
     AsfStream asfStream = new AsfStream(AsfStreamType.asfImage, testVideoFileName, 1.0, 2.0);
     Assert.IsNotNull(asfStream);
 }
Пример #17
0
 public void TryCreateInvalidFileNameAsfStream()
 {
     AsfStream asfStream = new AsfStream(AsfStreamType.asfStream, "", 0.0, 1.0);
 }
Пример #18
0
 public static WaveMemoryStream FromFile(string fileName, double startOffset, double endOffset)
 {
     using (AsfStream asfStream = new AsfStream(AsfStreamType.asfAudio, fileName, startOffset, endOffset))
     using (AsfAudio asfAudio = new AsfAudio(asfStream))
         return asfAudio.GetWaveStream();
 }
Пример #19
0
 public static Bitmap FromFile(string fileName, double offset)
 {
     using (AsfStream asfStream = new AsfStream(AsfStreamType.asfImage, fileName, offset))
         using (AsfImage asfImage = new AsfImage(asfStream))
             return(asfImage.GetImage());
 }
Пример #20
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);
 }
Пример #21
0
 public void TryCreateNotCoveredRangeAsfStream()
 {
     AsfStream asfStream = new AsfStream(AsfStreamType.asfAudio, testVideoFileName, 1.0, 5000);
 }
Пример #22
0
 public void TryCreateInvalidRangeAsfStream()
 {
     AsfStream asfStream = new AsfStream(AsfStreamType.asfAudio, testVideoFileName, -1.0, 4.0);
 }
Пример #23
0
 public void TryCreateImageFromAudioStream()
 {
     using (AsfStream asfStream = new AsfStream(AsfStreamType.asfAudio, testVideoFileName, 1.0))
     {
         AsfImage asfImage = new AsfImage(asfStream);
     }
 }
Пример #24
0
 public static WaveMemoryStream FromFile(string fileName, double startOffset, double endOffset)
 {
     using (AsfStream asfStream = new AsfStream(AsfStreamType.asfAudio, fileName, startOffset, endOffset))
         using (AsfAudio asfAudio = new AsfAudio(asfStream))
             return(asfAudio.GetWaveStream());
 }
Пример #25
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);
        }
Пример #26
0
 public void TryCreateInvalidFileAsfStream()
 {
     AsfStream asfStream = new AsfStream(AsfStreamType.asfStream, testBadFileName, 0, 1.0);
 }