コード例 #1
0
 public void CreatePlayableWaveMemoryStreamFluent()
 {
     WaveMemoryStream waveMemoryStream = WaveMemoryStream.FromFile(testVideoFileName)
                                         .From(1.0)
                                         .To(4.0);
     SoundPlayer soundPlayer = new SoundPlayer(waveMemoryStream);
 }
コード例 #2
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);
            }
        }
コード例 #3
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();
            }
        }
コード例 #4
0
 public void CreatePlayableWaveMemoryStreamStatic()
 {
     WaveMemoryStream waveMemoryStream = WaveMemoryStream.FromFile(testVideoFileName, 1.0, 4.0);
     SoundPlayer      soundPlayer      = new SoundPlayer(waveMemoryStream);
 }