예제 #1
0
        //private readonly System.Media.SoundPlayer _soundPlayer;

        public PCMPlayer(byte[] pcmSampleBytes, int samplingRate, int bitsPerSample, int channels)
        {
            using (WaveMemoryStream waveStream = new WaveMemoryStream(pcmSampleBytes, samplingRate, bitsPerSample, channels))
            {
                //_soundPlayer = new System.Media.SoundPlayer(waveStream);
            }
        }
예제 #2
0
 public void CreatePlayableWaveMemoryStreamFluent()
 {
     WaveMemoryStream waveMemoryStream = WaveMemoryStream.FromFile(testVideoFileName)
                                         .From(1.0)
                                         .To(4.0);
     SoundPlayer soundPlayer = new SoundPlayer(waveMemoryStream);
 }
예제 #3
0
        public void Rewind()
        {
            var asf = new AsfFile(filepath);

            asf.Open();
            soundStream = new AsfAudio(new AsfStream(asf, AsfStreamType.asfAudio, 0)).GetWaveStream();
            asf.Close();
        }
예제 #4
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);
        }
예제 #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);
                }
        }
예제 #6
0
 public PCMPlayer(string pcmFilePath, int samplingRate, ushort bitsPerSample, ushort channels)
 {
     using (System.IO.FileStream pcmSampleStream = System.IO.File.Open(pcmFilePath, System.IO.FileMode.Open))
     {
         byte[] pcmSampleBytes     = null;
         System.IO.BinaryReader br = new System.IO.BinaryReader(pcmSampleStream);
         long numBytes             = new System.IO.FileInfo(pcmFilePath).Length;
         pcmSampleBytes = br.ReadBytes((int)numBytes);
         using (WaveMemoryStream waveStream = new WaveMemoryStream(pcmSampleBytes, samplingRate, bitsPerSample, channels))
         {
             //_soundPlayer = new System.Media.SoundPlayer(waveStream);
         }
     }
 }
예제 #7
0
 public void Dispose()
 {
     if (soundStream != null)
     {
         soundStream.Dispose();
     }
     soundStream = null;
     if (video != null)
     {
         video.Dispose();
     }
     video = null;
     if (asf != null)
     {
         asf.Dispose();
     }
     asf = null;
 }
예제 #8
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) { }
        }
예제 #9
0
        public void CreatePlayableAudioSegmentFromOffsetRandom()
        {
            Random r = new Random();

            var ranges = Enumerable.Range(0, 100).Select(x =>
            {
                double startOffset = (testVideoFileDuration - 1) * r.NextDouble();
                double endOffset   = startOffset + r.Next(1, (int)(testVideoFileDuration - startOffset));
                return(new { startOffset, endOffset });
            }).ToArray();

            foreach (var range in ranges)
            {
                WaveMemoryStream waveMemoryStream = WaveMemoryStream.FromFile(testVideoFileName, range.startOffset, range.endOffset);
                Assert.IsNotNull(waveMemoryStream);

                //Soundplayer will throw an exception if this is not a valid Wave stream
                SoundPlayer soundPlayer = new SoundPlayer(waveMemoryStream);
            }
        }
예제 #10
0
 public void Dispose()
 {
     soundStream.Dispose();
     soundStream = null;
 }
예제 #11
0
        public static void ExecuteCommands(string fileName, Dictionary <string, object> switches)
        {
            try
            {
                if (switches.ContainsKey("PrintDuration")) // print file duration
                {
                    AsfFile           asfFile        = new AsfFile(fileName);
                    AsfFileProperties fileProperties = asfFile.GetAsfObject <AsfFileProperties>();
                    Console.WriteLine(string.Format("File {0} has a duration of {1}", fileName, fileProperties.Duration.ToString("mm':'ss\\.fff")));
                }
                else if (switches.ContainsKey("ExtractImage")) //extract an image thumb from a time offset
                {
                    //create thumb
                    double startOffset = (double)switches["StartOffset"];
                    string outputFile  = (string)switches["OutputFile"];

                    Bitmap bitmap = AsfImage.FromFile(fileName, startOffset);

                    if (switches.ContainsKey("Width"))
                    {
                        int width  = (int)switches["Width"];
                        int height = (int)(bitmap.Height * ((double)width / bitmap.Width));

                        Bitmap thumbBitmap = new Bitmap(width, height);
                        using (Graphics g = Graphics.FromImage(thumbBitmap))
                        {
                            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                            g.DrawImage(bitmap, 0, 0, width, height);
                        }
                        bitmap = thumbBitmap;
                    }

                    ImageFormat outputFormat = ImageFormat.Bmp;
                    if (outputFile.ToLower().Contains(".jpg"))
                    {
                        outputFormat = ImageFormat.Jpeg;
                    }
                    else if (outputFile.ToLower().Contains(".png"))
                    {
                        outputFormat = ImageFormat.Png;
                    }

                    bitmap.Save(outputFile, outputFormat);
                }
                else if (switches.ContainsKey("ExtractAudio")) //extract audio data from a time range
                {
                    double startOffset = (double)switches["StartOffset"];
                    double endOffset   = (double)switches["EndOffset"];
                    string outputFile  = (string)switches["OutputFile"];

                    WaveMemoryStream waveStream = WaveMemoryStream.FromFile(fileName, startOffset, endOffset);

                    using (FileStream fs = new FileStream(outputFile, FileMode.Create))
                        waveStream.WriteTo(fs);
                }
                else if (switches.ContainsKey("UpdateProperties")) //update content description properties
                {
                    AsfFile asfFile = new AsfFile(fileName);
                    AsfContentDescriptionObject contentDescription = asfFile.GetAsfObject <AsfContentDescriptionObject>();

                    if (contentDescription != null)
                    {
                        string author      = switches.ContainsKey("Author") ? (string)switches["Author"] : contentDescription.ContentProperties["Author"];
                        string copyright   = switches.ContainsKey("Copyright") ? (string)switches["Copyright"] : contentDescription.ContentProperties["Copyright"];
                        string title       = switches.ContainsKey("Title") ? (string)switches["Title"] : contentDescription.ContentProperties["Title"];
                        string description = switches.ContainsKey("Description") ? (string)switches["Description"] : contentDescription.ContentProperties["Description"];

                        AsfFile.From(fileName)
                        .WithAuthor(author)
                        .WithDescription(description)
                        .WithCopyright(copyright)
                        .WithTitle(title)
                        .Update();

                        Console.WriteLine(string.Format("Content description properties updated."));
                    }
                    else
                    {
                        Console.WriteLine(string.Format("No content description properties available."));
                    }
                }
            }
            catch (Exception)
            {
                PrintUsage();
            }
        }
예제 #12
0
 public void CreatePlayableWaveMemoryStreamStatic()
 {
     WaveMemoryStream waveMemoryStream = WaveMemoryStream.FromFile(testVideoFileName, 1.0, 4.0);
     SoundPlayer      soundPlayer      = new SoundPlayer(waveMemoryStream);
 }