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)); } }
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(); } }
void applicationWillTerminate(NSNotification aNotification) { if (logger.IsTraceEnabled) { logger.Trace("Disposing resources"); } try { if (player != null) { player.Dispose(); player = null; } if (factory != null) { factory.Dispose(); factory = null; } } catch (Exception exception) { if (logger.IsErrorEnabled) { logger.Error("An error trying to dispose resources", exception); } } }