Example #1
0
 public void TestPreparsedMediaCreate()
 {
     using (VlcMediaLibraryFactory factory = CreateNewFactory()) {
         factory.CreateSinglePlayers = true;
         PlayerOutput nullOutput = new PlayerOutput();
         //
         string path = GetSampleAudioPath();
         if (!System.IO.File.Exists(path))
         {
             Assert.Ignore("The sample file doesn't exists. Ignoring.");
         }
         MediaInput input = new MediaInput(MediaInputType.File,
                                           path);
         //
         using (Player player = factory.CreatePlayer(nullOutput)) {
             PreparsedMedia media = player.ParseMediaInput(input);
             media = player.ParseMediaInput(input);
             //
             Assert.IsTrue(media.ContainsAudio);
             Assert.IsFalse(media.ContainsVideo);
             //
             AudioTrackInfo[] tracks = media.GetAudioTracks();
             Assert.IsTrue(tracks.Length == 1, "There should be one audio track.");
             //
             VideoTrackInfo[] tracksVideo = media.GetVideoTracks();
             Assert.IsTrue(tracksVideo.Length == 0, "There shouldn't be any video tracks.");
         }
     }
 }
Example #2
0
        public void TestStreaming()
        {
            VlcMediaLibraryFactory factory = this.CreateNewFactory(new string[] {
            });
            VlcSinglePlayer playerStream   = (VlcSinglePlayer)factory.CreatePlayer(new
                                                                                   PlayerOutput(":sout=#transcode{vcodec=mp4v,vb=1024,acodec=mp4a,ab=192}:standard{mux=ts,dst=127.0.0.1:8080,access=udp}"));

            //
            string       filePath = GetTemporaryFilePath();
            PlayerOutput output   = new PlayerOutput();

            output.Files.Add(new OutFile(filePath));
            //
            VlcSinglePlayer playerReceive = (VlcSinglePlayer)factory.CreatePlayer(output);

            try {
                playerReceive.SetMediaInput(new MediaInput(MediaInputType.UnparsedMrl, "udp://127.0.0.1:8080"));
                playerStream.SetMediaInput(new MediaInput(MediaInputType.UnparsedMrl, "file://" + GetSampleVideoPath()));
                //
                playerStream.Play();
                //
                Thread.Sleep(1000);
                //
                playerReceive.Play();
                //
                Thread.Sleep(5000);
                //
                Assert.IsTrue(File.Exists(filePath));
                FileInfo info = new FileInfo(filePath);
                Assert.Greater(info.Length, 0);
                //
                playerReceive.Stop();
                playerStream.Stop();
            } finally {
                playerStream.Dispose();
                playerReceive.Dispose();
                factory.Dispose();
            }
        }
Example #3
0
 private void initializePlayer()
 {
     // that code will initialize factory if it is not initialized
     if (factory == null)
     {
         // this part of code will try to deploy VLC if it is necessary.
         // main idea - unzip libraries to specific place.
         VlcDeployment deployment = VlcDeployment.Default;
         // install library if it doesn't exist
         // NOTE: first parameter tells to check hash of deployed files to be sure about vlc version without loading it.
         // since vlc library can be initialized only once it is important not to load it during check
         // but it is still possible to check vlc version using libvlc_get_version, so if you want - pass second parameter
         // as 'true'.
         if (!deployment.CheckVlcLibraryExistence(false, false))
         {
             // install library
             deployment.Install(true);
         }
         // this is path to plugins. very important part of initialization of vlc.
         string path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "plugins");
         // we can use a lot of parameters there.
         // refer to vlc --help to learn more.
         factory = new VlcMediaLibraryFactory(new string[] { "--reset-config",
                                                             "--no-snapshot-preview",
                                                             "--aspect-ratio=16:9",
                                                             "--ignore-config",
                                                             "--intf", "rc",
                                                             "--no-osd",
                                                             "--plugin-path", path });
         // tell our factory to create new version of players
         // NOTE: if you change this to 'false' old version of implementation will be created
         // NOTE: old implementation remains for backward compatibility
         factory.CreateSinglePlayers = true;
         // we going to output to NSView instance:
         PlayerOutput output = new PlayerOutput(new VlcNativeMediaWindow(VideoView.NativePointer, VlcWindowType.NSObject));
         // we can save stream to a file:
         // output.Files.Add(new OutFile("filePath"));
         player = (VlcSinglePlayer)factory.CreatePlayer(output);
         // add event receiver to get known about player events
         player.EventsReceivers.Add(new EventReceiver(this));
     }
 }