Exemplo n.º 1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //Set libvlc.dll and libvlccore.dll directory path
            //VlcContext.LibVlcDllsPath = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_X86;
            //Set the vlc plugins directory path
            //VlcContext.LibVlcPluginsPath = CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_X86;
            VlcContext.LibVlcDllsPath    = @"VLCPortable\App\vlc\";
            VlcContext.LibVlcPluginsPath = @"VLCPortable\App\vlc\plugins\";

            //Set the startup options
            VlcContext.StartupOptions.IgnoreConfig                 = true;
            VlcContext.StartupOptions.LogOptions.LogInFile         = true;
            VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = true;
            VlcContext.StartupOptions.LogOptions.Verbosity         = VlcLogVerbosities.Debug;


            //Initialize the VlcContext
            VlcContext.Initialize();
            Application.Run(new Form1());


            //Close the VlcContext
            VlcContext.CloseAll();
        }
Exemplo n.º 2
0
        public static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Set libvlc.dll and libvlccore.dll directory path
            VlcContext.LibVlcDllsPath = @"C:\Projets\vlc-1.1.11"; // CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_AMD64;

            // Set the vlc plugins directory path
            VlcContext.LibVlcPluginsPath = @"C:\Projets\vlc-1.1.11\pugins"; //CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_AMD64;

            // Ignore the VLC configuration file
            VlcContext.StartupOptions.IgnoreConfig = true;

            // Enable file based logging
            VlcContext.StartupOptions.LogOptions.LogInFile = true;

            // Shows the VLC log console (in addition to the applications window)
            VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = true;

            // Set the log level for the VLC instance
            VlcContext.StartupOptions.LogOptions.Verbosity = VlcLogVerbosities.Debug;

            // Initialize the VlcContext
            VlcContext.Initialize();

            Application.Run(new VlcPlayer());

            // Close the VlcContext
            VlcContext.CloseAll();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 初始化流媒体播放器
        /// </summary>m
        public void VlcMediaPlayerInit(Action <VlcControl, string> vlcCallBack)
        {
            try
            {
                //vlc配置参数
                VlcContext.StartupOptions.IgnoreConfig                 = true;
                VlcContext.StartupOptions.LogOptions.LogInFile         = false;
                VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = false;
                VlcContext.StartupOptions.LogOptions.Verbosity         = VlcLogVerbosities.None;
                VlcContext.LibVlcPluginsPath = Environment.CurrentDirectory + "\\plugins";
                VlcContext.LibVlcDllsPath    = Environment.CurrentDirectory;
                //流媒体播放器初始化
                VlcContext.Initialize();
                //播放器实例生成
                vlcPlayer = new VlcControl();

                //// 创建绑定,绑定Image
                //Binding bing = new Binding();
                //bing.Source = vlcPlayer;
                //bing.Path = new PropertyPath("VideoSource");
                //img.SetBinding(Image.SourceProperty, bing);
                vlcCallBack(vlcPlayer, "VideoSource");
            }
            catch (Exception ex)
            {
                LogManage.WriteLog(this.GetType(), ex);
            }
            finally
            {
            }
        }
Exemplo n.º 4
0
        private void InitVlcContext()
        {
            VlcContext.CloseAll();

            //Set libvlc.dll and libvlccore.dll directory path
            VlcContext.LibVlcDllsPath = LibVlcDllsPath;
            //Set the vlc plugins directory path
            VlcContext.LibVlcPluginsPath = LibVlcPluginsPath;

            //Set the startup options (http://wiki.videolan.org/VLC_command-line_help)
            if (Options != null)
            {
                var optionList = Options.Split(' ');
                foreach (var option in optionList)
                {
                    VlcContext.StartupOptions.AddOption(option);
                }
            }

            //Set debug options
            VlcContext.StartupOptions.IgnoreConfig                 = true;
            VlcContext.StartupOptions.LogOptions.LogInFile         = DebugMode;
            VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = DebugMode;
            VlcContext.StartupOptions.LogOptions.Verbosity         = DebugMode ? VlcLogVerbosities.Debug : VlcLogVerbosities.None;

            VlcContext.Initialize();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Ensures the media player created.
        /// </summary>
        private void EnsureMediaPlayerCreated()
        {
            if (_initialized)
            {
                return;
            }

            var path = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);

            VlcContext.LibVlcDllsPath    = path;
            VlcContext.LibVlcPluginsPath = Path.Combine(path, "plugins");

            // Set the vlc plugins directory path
            //VlcContext.LibVlcDllsPath = @"C:\\Program Files (x86)\\VideoLAN\\VLC";
            //VlcContext.LibVlcPluginsPath = @"C:\\Program Files (x86)\\VideoLAN\\VLC\\plugins";

            /* Setting up the configuration of the VLC instance.
             * You can use any available command-line option using the AddOption function (see last two options).
             * A list of options is available at
             *     http://wiki.videolan.org/VLC_command-line_help
             * for example. */

            // Ignore the VLC configuration file
            VlcContext.StartupOptions.IgnoreConfig = true;

            // Enable file based logging
            VlcContext.StartupOptions.LogOptions.LogInFile = false;

            // Shows the VLC log console (in addition to the applications window)
            VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = false;

            // Set the log level for the VLC instance
            VlcContext.StartupOptions.LogOptions.Verbosity = VlcLogVerbosities.Debug;

            var configStrings = new List <string>
            {
                "-I",
                "dummy",
                "--ignore-config",
                "--no-osd",
                "--disable-screensaver",
                "--no-video-title-show"
            };

            if (_config.Configuration.VlcConfiguration.EnableGpuAcceleration)
            {
                configStrings.Add("--ffmpeg-hw");
            }

            foreach (var opt in configStrings)
            {
                VlcContext.StartupOptions.AddOption(opt);
            }

            // Initialize the VlcContext
            VlcContext.Initialize();

            _initialized = true;
        }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            bool isAMD64 = System.IO.Directory.Exists(CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_AMD64);
            bool isX86   = System.IO.Directory.Exists(CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_X86);

            if (isAMD64 || isX86)
            {
                try
                {
                    if (isAMD64)
                    {
                        //Set libvlc.dll and libvlccore.dll directory path
                        VlcContext.LibVlcDllsPath = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_AMD64;
                        //Set the vlc plugins directory path
                        VlcContext.LibVlcPluginsPath = CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_AMD64;
                    }
                    else
                    {
                        //Set libvlc.dll and libvlccore.dll directory path
                        VlcContext.LibVlcDllsPath = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_X86;
                        //Set the vlc plugins directory path
                        VlcContext.LibVlcPluginsPath = CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_X86;
                    }

                    //Set the startup options
                    VlcContext.StartupOptions.IgnoreConfig                 = true;
                    VlcContext.StartupOptions.LogOptions.LogInFile         = true;
                    VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = true;
                    VlcContext.StartupOptions.LogOptions.Verbosity         = VlcLogVerbosities.None;

                    //Initialize the VlcContext
                    VlcContext.Initialize();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed loading the optional VLC library. Channel previewing may not work correctly. Do you have the latest version of VLC installed? " + ex.Message);
                }
            }
            else
            {
                MessageBox.Show("VLC DLL files not found in either of the standard locations: " + CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_AMD64 + " or " + CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_X86);
            }

            Application.Run(new Main());

            if (isAMD64 || isX86)
            {
                try
                {
                    //Close the VlcContexttry
                    VlcContext.CloseAll();
                }
                catch (Exception) { }
            }
        }
Exemplo n.º 7
0
        public MainViewModel()
        {
            /* Setting up the configuration of the VLC instance.
             * You can use any available command-line option using the AddOption function (see last two options).
             * A list of options is available at
             *     http://wiki.videolan.org/VLC_command-line_help
             * for example. */
            // Ignore the VLC configuration file
            VlcContext.StartupOptions.IgnoreConfig = true;
            // Disable file based logging
            VlcContext.StartupOptions.LogOptions.LogInFile = false;
            // Disable the VLC log console (in addition to the applications window)
            VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = true;
            // Set the log level for the VLC instance
            VlcContext.StartupOptions.LogOptions.Verbosity = VlcLogVerbosities.Debug;
            // Disable showing the movie file name as an overlay
            VlcContext.StartupOptions.AddOption("--no-video-title-show");
            // Pauses the playback of a movie on the last frame
            VlcContext.StartupOptions.AddOption("--play-and-pause");

            var ofd = new OpenFileDialog();

            ofd.Filter           = "Libvlc Library (libvlc.dll)|*.dll|All Files|*.*";
            ofd.InitialDirectory = VlcContext.LibVlcDllsPath;
            ofd.Multiselect      = false;
            while (true)
            {
                var result = ofd.ShowDialog();
                if (result.HasValue && result.Value)
                {
                    try
                    {
                        // Set libvlc.dll and libvlccore.dll directory path
                        VlcContext.LibVlcDllsPath = ofd.File.Directory.FullName;
                        // Set the vlc plugins directory path
                        VlcContext.LibVlcPluginsPath = System.IO.Path.Combine(VlcContext.LibVlcDllsPath, "plugins");
                        // Initialize the VlcContext
                        VlcContext.Initialize();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Vlc.DotNet.silverlight.Sample", MessageBoxButton.OK);
                    }
                    if (VlcContext.IsInitialized)
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
        }
Exemplo n.º 8
0
        public void initVLC()
        {
            if (Environment.Is64BitOperatingSystem)
            {
                VlcContext.LibVlcDllsPath = @"VLC\x86";
                // Set the vlc plugins directory path
                VlcContext.LibVlcPluginsPath = @"VLC\x86\plugins";
            }
            else
            {
                // Set libvlc.dll and libvlccore.dll directory path
                VlcContext.LibVlcDllsPath = @"VLC\x86";
                // Set the vlc plugins directory path
                VlcContext.LibVlcPluginsPath = @"VLC\x86\plugins";
            }

            // Ignore the VLC configuration file
            VlcContext.StartupOptions.IgnoreConfig = true;

            // Enable file based logging
            VlcContext.StartupOptions.LogOptions.LogInFile = true;

            // Shows the VLC log console (in addition to the applications window)
            VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = false;

            // Set the log level for the VLC instance
            //VlcContext.StartupOptions.LogOptions.Verbosity = VlcLogVerbosities.Warnings;
            VlcContext.StartupOptions.AddOption("--ffmpeg-hw");
            // Disable showing the movie file name as an overlay
            VlcContext.StartupOptions.AddOption("--no-video-title-show");
            VlcContext.StartupOptions.AddOption("--rtsp-tcp");
            VlcContext.StartupOptions.AddOption("--rtsp-mcast");
            // VlcContext.StartupOptions.AddOption("--rtsp-host=192.168.10.35");
            // VlcContext.StartupOptions.AddOption("--sap-addr=192.168.10.35");
            VlcContext.StartupOptions.AddOption("--rtsp-port=8554");
            VlcContext.StartupOptions.AddOption("--rtp-client-port=8554");
            VlcContext.StartupOptions.AddOption("--sout-rtp-rtcp-mux");
            VlcContext.StartupOptions.AddOption("--rtsp-wmserver");


            VlcContext.StartupOptions.AddOption("--file-caching=18000");
            VlcContext.StartupOptions.AddOption("--sout-rtp-caching=18000");
            VlcContext.StartupOptions.AddOption("--sout-rtp-port=8554");
            VlcContext.StartupOptions.AddOption("--sout-rtp-proto=tcp");
            VlcContext.StartupOptions.AddOption("--network-caching=1000");

            // Pauses the playback of a movie on the last frame
            VlcContext.StartupOptions.AddOption("--play-and-pause");
            VlcContext.CloseAll();
            // Initialize the VlcContext
            VlcContext.Initialize();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Constructor of VlcControl
        /// </summary>
        public VlcControl()
        {
            if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
            {
                return;
            }

            VideoBrush = new ImageBrush();

            if (!VlcContext.IsInitialized)
            {
                VlcContext.Initialize();
            }

            VlcContext.HandleManager.MediaPlayerHandles[this] = VlcContext.InteropManager.MediaPlayerInterops.NewInstance.Invoke(VlcContext.HandleManager.LibVlcHandle);
            AudioProperties    = new VlcAudioProperties(this);
            VideoProperties    = new VlcVideoProperties(this);
            LogProperties      = new VlcLogProperties();
            Medias             = new VlcMediaListPlayer(this);
            AudioOutputDevices = new VlcAudioOutputDevices();

            EventsHelper.ExecuteRaiseEventDelegate =
                delegate(Delegate singleInvoke, object sender, object arg)
            {
                if (Dispatcher.CheckAccess())
                {
                    Dispatcher.Invoke(DispatcherPriority.Normal, singleInvoke, sender, arg);
                }
                else
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Normal, singleInvoke, sender, arg);
                }
            };
            InitEvents();

            myVideoLockCallback         = LockCallback;
            myVideoLockCallbackHandle   = GCHandle.Alloc(myVideoLockCallback);
            myVideoUnlockCallback       = UnlockCallback;
            myVideoUnlockCallbackHandle = GCHandle.Alloc(myVideoUnlockCallback);

            myVideoSetFormat       = VideoSetFormat;
            myVideoSetFormatHandle = GCHandle.Alloc(myVideoSetFormat);
            myVideoCleanup         = VideoCleanup;
            myVideoCleanupHandle   = GCHandle.Alloc(myVideoCleanup);

            CompositionTarget.Rendering += CompositionTargetRendering;

            VlcContext.InteropManager.MediaPlayerInterops.VideoInterops.SetFormatCallbacks.Invoke(VlcContext.HandleManager.MediaPlayerHandles[this], myVideoSetFormat, myVideoCleanup);
            VlcContext.InteropManager.MediaPlayerInterops.VideoInterops.SetCallbacks.Invoke(VlcContext.HandleManager.MediaPlayerHandles[this], myVideoLockCallback, myVideoUnlockCallback, null, IntPtr.Zero);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Constructor of VlcControl
        /// </summary>
        public VlcControl()
        {
            if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
            {
                return;
            }

            VideoBrush = new ImageBrush();

            if (!VlcContext.IsInitialized)
            {
                VlcContext.Initialize();
            }

            VlcContext.HandleManager.MediaPlayerHandles[this] = VlcContext.InteropManager.MediaPlayerInterops.NewInstance.Invoke(VlcContext.HandleManager.LibVlcHandle);
            AudioProperties    = new VlcAudioProperties(this);
            VideoProperties    = new VlcVideoProperties(this);
            LogProperties      = new VlcLogProperties();
            AudioOutputDevices = new VlcAudioOutputDevices();

            EventsHelper.ExecuteRaiseEventDelegate =
                delegate(Delegate singleInvoke, object sender, object arg)
            {
                var dispatcherObject = singleInvoke.Target as DispatcherObject;
                if (dispatcherObject == null)
                {
                    singleInvoke.DynamicInvoke(sender, arg);
                    return;
                }
                if (EventsHelper.CanRaiseEvent)
                {
                    dispatcherObject.Dispatcher.Invoke(singleInvoke, new[] { sender, arg });
                }
            };
            InitEvents();

            myVideoLockCallback       = LockCallback;
            myVideoLockCallbackHandle = GCHandle.Alloc(myVideoLockCallback);

            myVideoSetFormat       = VideoSetFormat;
            myVideoSetFormatHandle = GCHandle.Alloc(myVideoSetFormat);
            myVideoCleanup         = VideoCleanup;
            myVideoCleanupHandle   = GCHandle.Alloc(myVideoCleanup);

            CompositionTarget.Rendering += CompositionTargetRendering;

            VlcContext.InteropManager.MediaPlayerInterops.VideoInterops.SetFormatCallbacks.Invoke(VlcContext.HandleManager.MediaPlayerHandles[this], myVideoSetFormat, myVideoCleanup);
            VlcContext.InteropManager.MediaPlayerInterops.VideoInterops.SetCallbacks.Invoke(VlcContext.HandleManager.MediaPlayerHandles[this], myVideoLockCallback, null, null, IntPtr.Zero);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Constructor of VlcControl
        /// </summary>
        public VlcControl()
        {
            if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
            {
                return;
            }
            if (!VlcContext.IsInitialized)
            {
                VlcContext.Initialize();
            }
            VlcContext.HandleManager.MediaPlayerHandles[this] =
                VlcContext.InteropManager.MediaPlayerInterops.NewInstance.Invoke(
                    VlcContext.HandleManager.LibVlcHandle);
            AudioProperties    = new VlcAudioProperties(this);
            VideoProperties    = new VlcVideoProperties(this);
            Medias             = new VlcMediaListPlayer(this);
            LogProperties      = new VlcLogProperties();
            AudioOutputDevices = new VlcAudioOutputDevices();

            EventsHelper.ExecuteRaiseEventDelegate =
                delegate(Delegate singleInvoke, object sender, object arg)
            {
                var syncInvoke = singleInvoke.Target as ISynchronizeInvoke;
                if (syncInvoke == null)
                {
                    singleInvoke.DynamicInvoke(new [] { sender, arg });
                    return;
                }
                try
                {
                    if (syncInvoke.InvokeRequired)
                    {
                        syncInvoke.Invoke(singleInvoke, new [] { sender, arg });
                    }
                    else
                    {
                        singleInvoke.DynamicInvoke(sender, arg);
                    }
                }
                catch (ObjectDisposedException)
                {
                    //Because IsDisposed was true and IsDisposed could be false now...
                }
            };

            InitEvents();
            HandleCreated += OnHandleCreated;
        }
Exemplo n.º 12
0
        private static void SetUpVlcContext()
        {
            //Set libvlc.dll and libvlccore.dll directory path
            VlcContext.LibVlcDllsPath = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_AMD64;
            //Set the vlc plugins directory path
            VlcContext.LibVlcPluginsPath = CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_AMD64;

            //Set the startup options
            VlcContext.StartupOptions.IgnoreConfig                 = true;
            VlcContext.StartupOptions.LogOptions.LogInFile         = false;
            VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = false;
            VlcContext.StartupOptions.LogOptions.Verbosity         = VlcLogVerbosities.None;

            //Initialize the VlcContext
            VlcContext.Initialize();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VlcPlayer"/> class.
        /// </summary>
        public VideoPlayerControl()
        {
            // Set libvlc.dll and libvlccore.dll directory path
            VlcContext.LibVlcDllsPath = "."; //@"C:\Program Files\VideoLAN\vlc-1.2.0";

            // Set the vlc plugins directory path
            VlcContext.LibVlcPluginsPath = @".\plugins"; //@"C:\Program Files\VideoLAN\vlc-1.2.0\plugins";

            /* Setting up the configuration of the VLC instance.
             * You can use any available command-line option using the AddOption function (see last two options).
             * A list of options is available at
             *     http://wiki.videolan.org/VLC_command-line_help
             * for example. */

            // Ignore the VLC configuration file
            VlcContext.StartupOptions.IgnoreConfig = true;

            // Enable file based logging
            VlcContext.StartupOptions.LogOptions.LogInFile = true;

            // Shows the VLC log console (in addition to the applications window)
#if DEBUG
            VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = true;
#endif

            // Set the log level for the VLC instance
            VlcContext.StartupOptions.LogOptions.Verbosity = VlcLogVerbosities.Debug;

            // Disable showing the movie file name as an overlay
            VlcContext.StartupOptions.AddOption("--no-video-title-show");

            // Pauses the playback of a movie on the last frame
            VlcContext.StartupOptions.AddOption("--play-and-pause");

            VlcContext.StartupOptions.AddOption("--file-caching=2000");
            VlcContext.StartupOptions.AddOption("--ffmpeg-skiploopfilter=4");

            // Initialize the VlcContext
            VlcContext.Initialize();

            InitializeComponent();

            myVlcControl.VideoProperties.Scale = 2.0f;
            myVlcControl.PositionChanged      += VlcControlOnPositionChanged;
            //myVlcControl.TimeChanged += VlcControlOnTimeChanged;
            //Closing += MainWindowOnClosing;
        }
Exemplo n.º 14
0
        // Public Methods (1) 

        public static void InitVLC()
        {
            var appDir = new DirectoryInfo(Environment.CurrentDirectory);
            var vlcDir = new DirectoryInfo(Path.Combine(appDir.FullName,
                                                        "vlc"));

            VlcContext.LibVlcDllsPath    = vlcDir.FullName;
            VlcContext.LibVlcPluginsPath = Path.Combine(vlcDir.FullName,
                                                        "plugins");

            VlcContext.StartupOptions.IgnoreConfig                 = true;
            VlcContext.StartupOptions.LogOptions.LogInFile         = false;
            VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = false;
            VlcContext.StartupOptions.LogOptions.Verbosity         = VlcLogVerbosities.Warnings;

            VlcContext.Initialize();
        }
Exemplo n.º 15
0
        public bool IsVlcLibDirectoryValid(string vlcLibDirectory)
        {
            var oldValue = VlcContext.LibVlcDllsPath;
            var result   = true;

            VlcContext.LibVlcDllsPath = vlcLibDirectory;
            try
            {
                VlcContext.Initialize();
            }
            catch (Exception ex)
            {
                myErrors["VlcLibDirectory"] = ex.Message;
                result = false;
            }
            finally
            {
                VlcContext.LibVlcDllsPath = oldValue;
            }
            return(result);
        }
Exemplo n.º 16
0
        public static void Init()
        {
            if (!IsAvailable)
            {
                throw new InvalidOperationException("VLC is not available (not installed).");
            }

            //Set libvlc.dll and libvlccore.dll directory path
            //VlcContext.LibVlcDllsPath = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_AMD64;
            //Set the vlc plugins directory path
            //VlcContext.LibVlcPluginsPath = CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_AMD64;

            // TODO: what happens if VLC is not available?

            //Set the startup options
            VlcContext.StartupOptions.IgnoreConfig = true;
            //VlcContext.StartupOptions.LogOptions.LogInFile = true;
            //VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = true;
            VlcContext.StartupOptions.LogOptions.Verbosity = VlcLogVerbosities.Debug;
            VlcContext.StartupOptions.AddOption("--no-osd");
            VlcContext.LibVlcDllsPath    = Path;
            VlcContext.LibVlcPluginsPath = Path + @"\plugins";

            //Initialize the VlcContext
            try
            {
                VlcContext.Initialize();
            }
            catch (FileNotFoundException)
            {
                throw new InvalidOperationException("VLC is not available (libvlc not found). Try installing the 32-bit version of VLC.");
            }
            catch (TargetInvocationException)
            {
                throw new InvalidOperationException("VLC could not be loaded. Try installing the latest version (or any version >= 1.2).");
            }

            IsInitialized = true;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="YoutubeAudioPlayer"/> class.
        /// </summary>
        public YoutubeAudioPlayer()
        {
            if (Environment.Is64BitOperatingSystem)
            {
                VlcContext.LibVlcDllsPath    = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_AMD64;
                VlcContext.LibVlcPluginsPath = CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_AMD64;
            }

            else
            {
                VlcContext.LibVlcDllsPath    = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_X86;
                VlcContext.LibVlcPluginsPath = CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_X86;
            }

            VlcContext.StartupOptions.IgnoreConfig = true;

            VlcContext.Initialize();

            this.player = new VlcControl();

            this.player.TimeChanged += (sender, e) => this.CheckSongFinished();
        }
        static bool Init(string path)
        {
            if (path == null)
            {
                if (!_timer.IsEnabled)
                {
                    _timer.Start();
                }
                return(false);
            }

            try
            {
                //Set libvlc.dll and libvlccore.dll directory path
                VlcContext.LibVlcDllsPath = path;
                //Set the vlc plugins directory path
                VlcContext.LibVlcPluginsPath = path + @"\plugins";

                if (debug)
                {
                    VlcContext.StartupOptions.LogOptions.LogInFile         = true;
                    VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = true;
                    VlcContext.StartupOptions.LogOptions.Verbosity         = VlcLogVerbosities.Debug;
                }

                VlcContext.Initialize();
                InvokeVlcInitializedEvent();
                _timer.Stop();
                return(true);
            }
            catch (Exception)
            {
                if (!_timer.IsEnabled)
                {
                    _timer.Start();
                }
                return(false);
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Pre Init all things need for VLC
        /// </summary>
        private void PreInitVlc()
        {
            //Set libvlc.dll and libvlccore.dll directory path
            VlcContext.LibVlcDllsPath = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_X86;
            //Set the vlc plugins directory path
            VlcContext.LibVlcPluginsPath = CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_X86;

            //switch to 64-bit mode
            //MessageBox.Show(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"VideoLAN\VLC"));
            //VlcContext.LibVlcDllsPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"VideoLAN\VLC");
            //VlcContext.LibVlcPluginsPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"VideoLAN\VLC\plugins");


            //Set the startup options
            //VlcContext.StartupOptions.IgnoreConfig = true;
            //VlcContext.StartupOptions.LogOptions.LogInFile = false;
            //VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = false;

            //Initialize the VlcContext
            VlcContext.Initialize();

            //create instance
            vlcPlayer = new VlcControl();
        }
        protected override async void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            try
            {
                if (e.Args.Length == 0)
                {
                    Shutdown();
                    return;
                }
                //MessageBox.Show("edw");
                var  source       = new TaskCompletionSource <object>();
                var  handleSource = new TaskCompletionSource <object>();
                bool exited       = false;
                client = new TcpProcessInteropClient(int.Parse(e.Args[0]));
                client.Register("initialize", payload =>
                {
                    //MessageBox.Show("init");
                    if (exited)
                    {
                        return(null);
                    }

                    source     = new TaskCompletionSource <object>();
                    var path   = payload[0].ToString();
                    _arguments = payload[1].ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    bool init = false;
                    if (!File.Exists(Path.Combine(path, "libvlc.dll")))
                    {
                        Current.Shutdown();
                        return(null);
                    }

                    var pluginsPath              = Path.Combine(path, "plugins");
                    VlcContext.LibVlcDllsPath    = path;
                    VlcContext.LibVlcPluginsPath = pluginsPath;

                    VlcContext.StartupOptions.IgnoreConfig                 = true;
                    VlcContext.StartupOptions.LogOptions.LogInFile         = false;
                    VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = false;
                    VlcContext.StartupOptions.LogOptions.Verbosity         = VlcLogVerbosities.None;
                    VlcContext.StartupOptions.AddOption("--input-timeshift-granularity=0");
                    VlcContext.StartupOptions.AddOption("--auto-preparse");
                    VlcContext.StartupOptions.AddOption("--album-art=0");
                    //VlcContext.StartupOptions.AddOption("--overlay=1");
                    //VlcContext.StartupOptions.AddOption("--deinterlace=-1");
                    //VlcContext.StartupOptions.AddOption("--network-caching=1500");


                    foreach (var arg in _arguments)
                    {
                        try
                        {
                            //MessageBox.Show(arg);
                            VlcContext.StartupOptions.AddOption(arg.ToString());
                        }
                        catch
                        {
                        }
                    }
                    try
                    {
                        VlcContext.Initialize();
                        init = true;
                    }
                    catch (Exception)
                    {
                        //MessageBox.Show(ex.Message);
                        Application.Current.Shutdown();
                    }
                    source.SetResult(null);
                    return(init ? new object[] { } : null);
                });
                client.Register("shutdown", async args =>
                {
                    exited = true;
                    if (source != null)
                    {
                        await source.Task;
                    }
                    await Dispatcher.BeginInvoke(new Action(() =>
                    {
                        if (_vlc != null)
                        {
                            _vlc.Stop();
                            _vlc.Dispose();
                        }
                        if (VlcContext.IsInitialized)
                        {
                            VlcContext.CloseAll();
                        }
                        Shutdown();
                    }));
                    return(new object[] { });
                });
                client.Register("handle", async args =>
                {
                    if (exited)
                    {
                        return(null);
                    }
                    await Dispatcher.BeginInvoke(new Action(() =>
                    {
                        if (_vlc != null)
                        {
                            _vlc.Dispose();
                        }
                        _vlc = new VlcControlHeadless((IntPtr)long.Parse(args[0].ToString()));
                        SetupPlayer();
                    }));
                    return(new object[] { });
                });
                client.Subscribe("play", args =>
                {
                    if (!string.IsNullOrEmpty(args[0].ToString()))
                    {
                        _duration = TimeSpan.FromSeconds(0);
                        var split = args[0].ToString().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        //var split2 = _arguments.ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        _currentMedia = new LocationMedia(split[0]);
                        SetHandlersForMedia(_currentMedia);

                        _vlc.Media = _currentMedia;
                        if (split.Length > 1)
                        {
                            foreach (var extra in split.Skip(1))
                            {
                                //MessageBox.Show(extra);
                                _currentMedia.AddOption(extra);
                            }
                        }
                    }
                    else
                    {
                        _vlc.Play();
                    }
                });
                client.Subscribe("position", args =>
                {
                    _vlc.Position = float.Parse(args[0].ToString());
                });
                client.Subscribe("pause", args =>
                {
                    _vlc.Pause();
                });
                client.Subscribe("next", args =>
                {
                    try
                    {
                        if (_currentMedia as LocationMedia == null)
                        {
                            return;
                        }
                        var subitems = (_currentMedia as LocationMedia).SubItems;
                        var cmedia   = _vlc.Media as LocationMedia;
                        if (cmedia == null)
                        {
                            return;
                        }
                        var index = subitems.IndexOf(subitems.First(m => m.MRL == cmedia.MRL));
                        if (subitems.Count > 0 && index < subitems.Count - 1)
                        {
                            _vlc.Next();
                        }
                    }
                    catch
                    {
                    }
                });
                client.Subscribe("previous", args =>
                {
                    try
                    {
                        if (_currentMedia as LocationMedia == null)
                        {
                            return;
                        }
                        var subitems = (_currentMedia as LocationMedia).SubItems;
                        var cmedia   = _vlc.Media as LocationMedia;
                        if (cmedia == null)
                        {
                            return;
                        }
                        var index = subitems.IndexOf(subitems.First(m => m.MRL == cmedia.MRL));
                        if (subitems.Count > 0 && index > 0)
                        {
                            _vlc.Previous();
                        }
                    }
                    catch
                    {
                    }
                });
                client.Subscribe("next-subtitle", args =>
                {
                    if (_vlc.VideoProperties.SpuDescription.Next != null && _vlc.VideoProperties.SpuDescription.Next.Id != _vlc.VideoProperties.CurrentSpuIndex)
                    {
                        _vlc.VideoProperties.CurrentSpuIndex = _vlc.VideoProperties.SpuDescription.Next.Id;
                    }
                    else
                    {
                        _vlc.VideoProperties.CurrentSpuIndex = -1;
                    }
                    _vlc.VideoProperties.SetSubtitleFile(null);
                });

                client.Subscribe("set-subtitles", args =>
                {
                    var title = args[0].ToString();
                    if (title == "-1" && _subtitles?.Any(kv => kv.Key.ToString() == title) == true)
                    {
                        _vlc.VideoProperties.CurrentSpuIndex = -1;
                        _vlc.VideoProperties.SetSubtitleFile(null);
                    }
                    else if (_subtitles.Count > 1)
                    {
                        _vlc.VideoProperties.CurrentSpuIndex = _subtitles.Keys.Skip(1).First();
                        _vlc.VideoProperties.SetSubtitleFile(null);
                    }
                });

                if (await client.ConnectAsync(5000))
                {
                    client.Start();
                }
                else
                {
                    Shutdown();
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VlcPlayer"/> class.
        /// </summary>
        public MediaPlayer(string parameters, string callingPage)
        {
            _callingPage = callingPage;
            Messenger.Default.Register <KeyEventArgs>(this, MainWindow_KeyDown);

            if (Directory.Exists("C:\\Program Files\\VideoLAN\\VLC"))
            {
                // Set libvlc.dll and libvlccore.dll directory path
                VlcContext.LibVlcDllsPath = @"C:\Program Files\VideoLAN\VLC";

                // Set the vlc plugins directory path
                VlcContext.LibVlcPluginsPath = @"C:\Program Files\VideoLAN\VLC\plugins";
            }
            else
            {
                // Set libvlc.dll and libvlccore.dll directory path
                VlcContext.LibVlcDllsPath = @"C:\Program Files (x86)\VideoLAN\VLC";

                // Set the vlc plugins directory path
                VlcContext.LibVlcPluginsPath = @"C:\Program Files (x86)\VideoLAN\VLC\plugins";
            }



            /* Setting up the configuration of the VLC instance.
             * You can use any available command-line option using the AddOption function (see last two options).
             * A list of options is available at
             *     http://wiki.videolan.org/VLC_command-line_help
             * for example. */

            // Ignore the VLC configuration file
            VlcContext.StartupOptions.IgnoreConfig = true;

            // Enable file based logging
            VlcContext.StartupOptions.LogOptions.LogInFile = false;

            // Shows the VLC log console (in addition to the applications window)
            VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = false;

            // Set the log level for the VLC instance
            VlcContext.StartupOptions.LogOptions.Verbosity = VlcLogVerbosities.Debug;

            // Disable showing the movie file name as an overlay
            VlcContext.StartupOptions.AddOption("--no-video-title-show");

            // Pauses the playback of a movie on the last frame
            //VlcContext.StartupOptions.AddOption("--play-and-pause");

            // Initialize the VlcContext
            VlcContext.Initialize();

            InitializeComponent();

            myVlcControl.VideoProperties.Scale = 2.0f;
            myVlcControl.PositionChanged      += VlcControlOnPositionChanged;
            myVlcControl.TimeChanged          += VlcControlOnTimeChanged;

            myVlcControl.Media = new PathMedia(parameters);
            myVlcControl.Media.ParsedChanged += MediaOnParsedChanged;
            myVlcControl.Play();
        }