Ejemplo n.º 1
0
        public VlcMediaLibraryFactory CreateNewFactory()
        {
            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location), "plugins");
            VlcMediaLibraryFactory factory = new VlcMediaLibraryFactory(new string[] { "--reset-config",
                                                                                       "--no-snapshot-preview",
                                                                                       "--aspect-ratio=16:9",
                                                                                       "--ignore-config",
                                                                                       "--intf", "rc",
                                                                                       "--no-osd",
                                                                                       "--plugin-path", path }
                                                                        );

            return(factory);
        }
Ejemplo n.º 2
0
        public VlcMediaLibraryFactory CreateNewFactory(string[] parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            string        path      = Path.Combine(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location), "plugins");
            List <string> paramList = new List <string>(parameters.Length + 2);

            paramList.AddRange(parameters);
            paramList.Add("--plugin-path");
            paramList.Add(path);
            VlcMediaLibraryFactory factory = new VlcMediaLibraryFactory(paramList.ToArray());

            return(factory);
        }
Ejemplo n.º 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));
     }
 }
Ejemplo n.º 4
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();
            }
        }
Ejemplo n.º 5
0
 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);
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks for existence of library.
        /// </summary>
        /// <param name="checkHashes"><code>True</code> to compare hashes.</param>
        /// <param name="tryLoad"><code>True</code> to try load of library.</param>
        /// <returns><code>False</code> if library does not exists.</returns>
        public bool CheckVlcLibraryExistence(bool checkHashes, bool tryLoad)
        {
            //
            VlcDeploymentFailReason failReason = deploymentFailReason;

            try {
                deploymentFailReason = 0;
                DirectoryInfo info = new DirectoryInfo(deploymentLocation);
                if (!info.Exists)
                {
                    deploymentFailReason = VlcDeploymentFailReason.EmptyDeployment;
                    return(false);
                }
                else
                {
                    //
                    FileInfo[] files = info.GetFiles();
                    //
                    List <string> fileNames = new List <string> ();
                    //
                    foreach (FileInfo file in files)
                    {
                        fileNames.Add(file.Name);
                    }
                    //
                    foreach (KeyValuePair <string, string> pair in deploymentContent)
                    {
                        string filePath = pair.Key.Replace('\\', Path.DirectorySeparatorChar);
                        if (filePath.StartsWith(Path.DirectorySeparatorChar.ToString()))
                        {
                            filePath = filePath.Substring(1);
                        }
                        string fileHash = pair.Value;
                        //
                        string fullFilePath = Path.GetFullPath(Path.Combine(deploymentLocation, filePath));
                        if (filePath.LastIndexOf(Path.DirectorySeparatorChar) > 0)
                        {
                            string directoryName = Path.GetDirectoryName(filePath);
                            string directoryPath = Path.Combine(deploymentLocation, directoryName);
                            if (!Directory.Exists(directoryPath))
                            {
                                deploymentFailReason = FailReason | VlcDeploymentFailReason.NotAllFilesDeployed;
                                return(false);
                            }
                            else
                            {
                                if (!File.Exists(fullFilePath))
                                {
                                    deploymentFailReason = FailReason | VlcDeploymentFailReason.NotAllFilesDeployed;
                                    return(false);
                                }
                            }
                        }
                        else
                        {
                            // this is file in root
                            if (!fileNames.Contains(filePath))
                            {
                                deploymentFailReason = FailReason | VlcDeploymentFailReason.NotAllFilesDeployed;
                                return(false);
                            }
                        }
                        if (checkHashes)
                        {
                            using (Stream stream = File.Open(fullFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                                byte[] hash       = hashReceiver.ComputeHash(stream);
                                string hashBase64 = Convert.ToBase64String(hash);
                                if (string.Compare(fileHash, hashBase64) != 0)
                                {
                                    deploymentFailReason = FailReason | VlcDeploymentFailReason.InvalidHashOfFile;
                                    return(false);
                                }
                            }
                        }
                    }
                    //
                }
                //
                if (tryLoad)
                {
                    try {
                        List <string> parameters = new List <string>();
                        if (osType == VlcDeployment.DeterminedOSType.MacOS)
                        {
                            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "plugins");
                            parameters.Add("--plugin-path");
                            parameters.Add(path);
                        }
                        using (VlcMediaLibraryFactory factory = new VlcMediaLibraryFactory(parameters.ToArray())) {
                            string version = factory.Version;
                            if (string.Compare(version, vlcVersion, StringComparison.Ordinal) != 0)
                            {
                                deploymentFailReason = FailReason | VlcDeploymentFailReason.LibraryVersionDiffers;
                            }
                            return(true);
                        }
                    } catch (VlcInternalException exc) {
                        deploymentFailReason = FailReason | VlcDeploymentFailReason.LibraryCannotBeLoaded;
                        if (logger.IsWarnEnabled)
                        {
                            logger.Warn("Cannot check vlc version.", exc);
                        }
                    }
                }
                return(FailReason == 0);
            } catch (Exception) {
                deploymentFailReason = failReason;
                throw;
            }
        }