static IntPtr SelectNativeCtor(LibVLC libVLC, string mrl, FromType type) { if (libVLC == null) { throw new ArgumentNullException(nameof(libVLC)); } if (string.IsNullOrEmpty(mrl)) { throw new ArgumentNullException(nameof(mrl)); } var mrlPtr = Utf8StringMarshaler.GetInstance().MarshalManagedToNative(mrl); if (mrlPtr == IntPtr.Zero) { throw new ArgumentException($"error marshalling {mrl} to UTF-8 for native interop"); } switch (type) { case FromType.FromLocation: return(Native.LibVLCMediaNewLocation(libVLC.NativeReference, mrlPtr)); case FromType.FromPath: return(Native.LibVLCMediaNewPath(libVLC.NativeReference, mrlPtr)); case FromType.AsNode: return(Native.LibVLCMediaNewAsNode(libVLC.NativeReference, mrlPtr)); default: return(IntPtr.Zero); } }
/// <summary> /// Post a login answer. /// After this call, the instance won't be valid anymore /// </summary> /// <param name="username">valid non-empty string</param> /// <param name="password">valid string</param> /// <param name="store">if true stores the credentials</param> /// <returns></returns> public bool PostLogin(string username, string password, bool store) { if (_id == IntPtr.Zero) { throw new VLCException("Calling method on dismissed Dialog instance"); } if (username == null) { username = string.Empty; } if (password == null) { password = string.Empty; } var usernamePtr = Utf8StringMarshaler.GetInstance().MarshalManagedToNative(username); var passwordPtr = Utf8StringMarshaler.GetInstance().MarshalManagedToNative(password); var result = Native.LibVLCDialogPostLogin(_id, usernamePtr, passwordPtr, store) == 0; _id = IntPtr.Zero; return(result); }
/// <summary> /// Code taken from Vlc.DotNet /// </summary> /// <param name="data"></param> /// <param name="level"></param> /// <param name="ctx"></param> /// <param name="format"></param> /// <param name="args"></param> void OnLogInternal(IntPtr data, LogLevel level, IntPtr ctx, string format, IntPtr args) { if (_log == null) { return; } // Original source for va_list handling: https://stackoverflow.com/a/37629480/2663813 var byteLength = Native._vscprintf(format, args) + 1; var utf8Buffer = Marshal.AllocHGlobal(byteLength); string formattedDecodedMessage; try { Native.vsprintf(utf8Buffer, format, args); formattedDecodedMessage = (string)Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(utf8Buffer); } finally { Marshal.FreeHGlobal(utf8Buffer); } GetLogContext(ctx, out var module, out var file, out var line); // Do the notification on another thread, so that VLC is not interrupted by the logging Task.Run(() => _log?.Invoke(NativeReference, new LogEventArgs(level, formattedDecodedMessage, module, file, line))); }
void OnAudioDevice(IntPtr ptr) { var deviceNamePtr = RetrieveEvent(ptr).Union.AudioDeviceChanged.Device; var deviceName = (string)Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(deviceNamePtr); _mediaPlayerAudioDevice?.Invoke(this, new MediaPlayerAudioDeviceEventArgs(deviceName)); }
void OnSnapshotTaken(IntPtr ptr) { var filenamePtr = RetrieveEvent(ptr).Union.MediaPlayerSnapshotTaken.Filename; var filename = (string)Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(filenamePtr); _mediaPlayerSnapshotTaken?.Invoke(this, new MediaPlayerSnapshotTakenEventArgs(filename)); }
/// <summary> /// Gets log message debug infos. /// /// This function retrieves self-debug information about a log message: /// - the name of the VLC module emitting the message, /// - the name of the source code module (i.e.file) and /// - the line number within the source code module. /// /// The returned module name and file name will be NULL if unknown. /// The returned line number will similarly be zero if unknown. /// </summary> /// <param name="logContext">The log message context (as passed to the <see cref="LogCallback"/>)</param> /// <param name="module">The module name storage.</param> /// <param name="file">The source code file name storage.</param> /// <param name="line">The source code file line number storage.</param> void GetLogContext(IntPtr logContext, out string module, out string file, out uint?line) { Native.LibVLCLogGetContext(logContext, out var modulePtr, out var filePtr, out var linePtr); line = linePtr == UIntPtr.Zero ? null : (uint?)linePtr.ToUInt32(); module = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(modulePtr) as string; file = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(filePtr) as string; }
/// <summary>Read the meta of the media.</summary> /// <param name="metadataType">the meta to read</param> /// <returns>the media's meta</returns> /// <remarks> /// If the media has not yet been parsed this will return NULL. /// </remarks> public string Meta(MetadataType metadataType) { var metaPtr = Native.LibVLCMediaGetMeta(NativeReference, metadataType); if (metaPtr == IntPtr.Zero) { return(string.Empty); } return(Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(metaPtr) as string); }
/// <summary> /// Get the name of a particular equalizer preset. /// This name can be used, for example, to prepare a preset label or menu in a user interface. /// </summary> /// <param name="index">index of the preset, counting from zero</param> /// <returns>preset name, or empty string if there is no such preset</returns> public string PresetName(uint index) => (string)Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(Native.LibVLCAudioEqualizerGetPresetName(index));
/// <summary>Gets a list of audio output devices for a given audio output module,</summary> /// <param name="audioOutputName"> /// <para>audio output name</para> /// <para>(as returned by libvlc_audio_output_list_get())</para> /// </param> /// <returns> /// <para>A NULL-terminated linked list of potential audio output devices.</para> /// <para>It must be freed with libvlc_audio_output_device_list_release()</para> /// </returns> /// <remarks> /// <para>libvlc_audio_output_device_set().</para> /// <para>Not all audio outputs support this. In particular, an empty (NULL)</para> /// <para>list of devices doesnotimply that the specified audio output does</para> /// <para>not work.</para> /// <para>The list might not be exhaustive.</para> /// <para>Some audio output devices in the list might not actually work in</para> /// <para>some circumstances. By default, it is recommended to not specify any</para> /// <para>explicit audio device.</para> /// <para>LibVLC 2.1.0 or later.</para> /// </remarks> public AudioOutputDevice[] AudioOutputDevices(string audioOutputName) => MarshalUtils.Retrieve(() => Native.LibVLCAudioOutputDeviceListGet(NativeReference, Utf8StringMarshaler.GetInstance().MarshalManagedToNative(audioOutputName)), MarshalUtils.PtrToStructure <AudioOutputDeviceStructure>, s => s.Build(), device => device.Next, Native.LibVLCAudioOutputDeviceListRelease);