示例#1
0
        private void LoadMpvDynamic()
        {
            var platform = PlatformCheck.RunningPlatform();

            if (platform == Platform.Windows)
            {
                _libMpvDll = LoadLibrary(_libMpvPath);  // "mpv-1.dll"); // The dll is included in the DEV builds by lachs0r: https://mpv.srsfckn.biz/
            }
            else if (platform == Platform.Linux)
            {
                _libMpvDll = dlopen(_libMpvPath, RTLD_NOW);  //("/usr/lib/x86_64-linux-gnu/libmpv.so.1", RTLD_NOW);
            }
            else
            {
                throw new NotImplementedException();
            }


            _mpvCreate            = (MpvCreate)GetDllType(typeof(MpvCreate), "mpv_create");
            _mpvInitialize        = (MpvInitialize)GetDllType(typeof(MpvInitialize), "mpv_initialize");
            _mpvTerminateDestroy  = (MpvTerminateDestroy)GetDllType(typeof(MpvTerminateDestroy), "mpv_terminate_destroy");
            _mpvCommand           = (MpvCommand)GetDllType(typeof(MpvCommand), "mpv_command");
            _mpvSetOption         = (MpvSetOption)GetDllType(typeof(MpvSetOption), "mpv_set_option");
            _mpvSetOptionString   = (MpvSetOptionString)GetDllType(typeof(MpvSetOptionString), "mpv_set_option_string");
            _mpvGetPropertyString = (MpvGetPropertystring)GetDllType(typeof(MpvGetPropertystring), "mpv_get_property");
            _mpvSetProperty       = (MpvSetProperty)GetDllType(typeof(MpvSetProperty), "mpv_set_property");
            _mpvFree            = (MpvFree)GetDllType(typeof(MpvFree), "mpv_free");
            _mpvObserveProperty = (MpvObserveProperty)GetDllType(typeof(MpvObserveProperty), "mpv_observe_property");
        }
 /// <summary>
 /// Attempt to auto detect prefered backends.
 /// </summary>
 /// <param name="file">The multimedia file to discover</param>
 /// <param name="path">Path to mplayer executable or mpv library</param>
 public static Discover Get(string file, string path)
 {
     if (PlatformCheck.RunningPlatform() == Platform.Windows)
     {
         return(DiscoverFactory.Windows(file, path));
     }
     else if (PlatformCheck.RunningPlatform() == Platform.Linux)
     {
         return(DiscoverFactory.Linux(file, path));
     }
     else if (PlatformCheck.RunningPlatform() == Platform.Mac)
     {
         return(DiscoverFactory.Mac(file, path));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
示例#3
0
        /// <summary>
        /// Attempt to auto detect prefered backends.
        /// </summary>
        /// <param name="handle">Handle.</param>
        /// <param name="path">Path to mplayer executable or mpv library</param>
        public static Player Get(long handle, string path)
        {
            // -path "/usr/lib/x86_64-linux-gnu/libmpv.so.1"

            if (PlatformCheck.RunningPlatform() == Platform.Windows)
            {
                return(PlayerFactory.Windows(handle, path));
            }
            else if (PlatformCheck.RunningPlatform() == Platform.Linux)
            {
                return(PlayerFactory.Linux(handle, path));
            }
            else if (PlatformCheck.RunningPlatform() == Platform.Mac)
            {
                return(PlayerFactory.Mac(handle, path));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
示例#4
0
        /*
         * public int ObserveProperty (string name, Action<object> action)
         * {
         *  //
         *  int returnValue = _mpvObserveProperty (_mpvHandle, (ulong)action.GetHashCode (), name, (int)MpvFormat.MPV_FORMAT_FLAG);
         *  if (returnValue < 0) {
         *      MpvError error = (MpvError)returnValue;
         *      throw new MPlayerControlException ($"ObserveProperty ({name}) error {error.ToString()}", returnValue);
         *  }
         * }
         */

        private object GetDllType(Type type, string name)
        {
            IntPtr address;
            var    platform = PlatformCheck.RunningPlatform();

            if (platform == Platform.Windows)
            {
                address = GetProcAddress(_libMpvDll, name);
            }
            else if (platform == Platform.Linux)
            {
                address = dlsym(_libMpvDll, name);
            }
            else
            {
                throw new NotImplementedException();
            }

            if (address != IntPtr.Zero)
            {
                return(Marshal.GetDelegateForFunctionPointer(address, type));
            }
            return(null);
        }