コード例 #1
0
ファイル: Program.cs プロジェクト: jonlawley/VlcDriver
        static void Main()
        {
            #region This region is only for use in this console example as ending the console will leave VLC running
            handler = ConsoleEventCallback;
            var osver = Environment.OSVersion;
            switch (osver.Platform)
            {
                case PlatformID.Win32NT:
                    SetConsoleCtrlHandler(handler, true);
                    break;
            }

            #endregion

            var input = new FileInfo(@"c:\Temp\inputVideo.avi");
            var output = new FileInfo(@"c:\Temp\outputVideo.mpg");

            if (!input.Exists)
            {
                throw new FileNotFoundException("Example app needs a file to convert", input.FullName);
            }

            var driver = new VlcDriver();
            //driver.VlcExePath = new FileInfo("/usr/bin/vlc"); - Only on Non Windows environments
            Job = driver.CreateVideoJob();
            Job.InputFile = input;
            Job.OutputFile = output;
            Job.VideoConfiguration.Format = VideoConfiguration.VlcVideoFormat.Mpeg2;
            Job.AudioConfiguration.Format = AudioConfiguration.ConversionFormats.Mpg;

            driver.StartJob(Job);

            while (Job.State != VlcJob.JobState.Finished)
            {
                Job.UpdateProgress();
                Console.Clear();
                Console.SetCursorPosition(0,0);
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("{0}% Complete. Remaining {1}", string.Format("{0:0.0#}", Job.PercentComplete * 100), Job.EstimatedTimeToCompletion.ToString(@"h\h\:m\m\:s\s", System.Globalization.CultureInfo.InvariantCulture));
                Thread.Sleep(1000);
            }
        }
コード例 #2
0
ファイル: VlcDriverTests.cs プロジェクト: jonlawley/VlcDriver
        public void TestWeGetJobStateChangedEventWhenConversionEnds()
        {
            var file = TestUtilities.GetTestFile("NeedinYou2SecWav.wav");
            var audioConfiguration = new AudioConfiguration
            {
                Format = AudioConfiguration.ConversionFormats.Mp3
            };

            var portAllocator = MockRepository.GenerateMock<IPortAllocator>();
            portAllocator.Expect(x => x.NewPort()).Return(42);

            var job = new VlcAudioJob(audioConfiguration, portAllocator, MockRepository.GenerateMock<IStatusParser>(), MockRepository.GenerateMock<IVlcStatusSource>(), new TimeSouce(), MockRepository.GenerateMock<ILogger>());
            Assert.AreEqual(VlcJob.JobState.NotStarted, job.State);
            job.InputFile = file;
            var expectedOutputFile = Path.Combine(TestUtilities.GetTestOutputDir(), "output.mp3");
            job.OutputFile = new FileInfo(expectedOutputFile);

            var starter = MockRepository.GenerateMock<IVlcStarter>();
            var instance = MockRepository.GenerateMock<IVlcInstance>();
            starter.Expect(x => x.Start(Arg<string>.Is.Anything, Arg<FileInfo>.Is.Anything)).Return(instance);
            var driver = new VlcDriver(starter);
            TestUtilities.SetVlcExeLocationOnNonStandardWindowsEnvironments(driver);
            Assert.AreEqual(0, driver.JobBag.Count);
            Assert.AreEqual(VlcJob.JobState.NotStarted, job.State);
            driver.StartJob(job);
            Assert.AreEqual(1, driver.JobBag.Count);
            Assert.AreEqual(VlcJob.JobState.Started, job.State);
            var eventHandlerWasCalled = false;
            driver.OnJobStateChange += (source, args) =>
            {
                eventHandlerWasCalled = true;
                Assert.AreEqual(job, args.Job);
            };
            instance.Raise(x => x.OnExited += null, instance, new EventArgs());
            Assert.IsTrue(eventHandlerWasCalled);
        }
コード例 #3
0
        public void TestVlcMp32WavJobActuallyGetsDone()
        {
            var file = TestUtilities.GetTestFile("NeedinYou2SecWavMp3128.mp3");
            var audioConfiguration = new AudioConfiguration
            {
                Format = AudioConfiguration.ConversionFormats.Wav
            };

            var portAllocator = MockRepository.GenerateMock<IPortAllocator>();
            portAllocator.Expect(x => x.NewPort()).Return(42);

            var job = new VlcAudioJob(audioConfiguration, portAllocator, MockRepository.GenerateMock<IStatusParser>(), MockRepository.GenerateMock<IVlcStatusSource>(), new TimeSouce(), MockRepository.GenerateMock<ILogger>());
            Assert.AreEqual(VlcJob.JobState.NotStarted, job.State);
            job.InputFile = file;
            var expectedOutputFile = Path.Combine(TestUtilities.GetTestOutputDir(), "output2.wav");
            job.OutputFile = new FileInfo(expectedOutputFile);

            var driver = new VlcDriver(new VlcStarter(MockRepository.GenerateMock<ILogger>()));
            TestUtilities.SetVlcExeLocationOnNonStandardWindowsEnvironments(driver);
            Assert.IsFalse(job.OutputFile.Exists, "output file already exists, cannot run test");
            driver.StartJob(job);
            Assert.AreEqual(1, driver.JobBag.Count);
            Assert.IsNotNull(job.Instance);
            Assert.IsNotNull(job.Instance.Process);
            Assert.AreEqual(VlcJob.JobState.Started, job.State);
            job.Instance.Process.WaitForExit();
            SleepToAllowEventHandler();
            Assert.AreEqual(VlcJob.JobState.Finished, job.State, "Job state was not set to finished afterwards");
            var newFileInfo = new FileInfo(job.OutputFile.FullName);
            Assert.IsTrue(newFileInfo.Exists);
            Assert.That(newFileInfo.Length, Is.EqualTo(368684).Within(AllowedOutputFileComparePercentage).Percent);
        }