Example #1
0
 public MpvWrapper(IntPtr systemHandle, MpvStatus mpvStatus)
 {
     SystemHandle = systemHandle;
     MpvStatus    = mpvStatus;
     MpvHandle    = Libmpv.mpv_create();
     Initialize();
     EventTask = new MpvEventTask(this, MpvStatus, EventTaskCancellationTokenSource).StartEventTask();
 }
Example #2
0
        private void DoCommand(params string[] commands)
        {
            var err = Libmpv.ExecuteCommand(MpvHandle, commands);

            if (err != Libmpv.mpv_error.MPV_ERROR_SUCCESS)
            {
                throw new LibMpvException(err);
            }
        }
Example #3
0
        private void Initialize()
        {
            Libmpv.set_property_string(MpvHandle, "wid", SystemHandle.ToString());
            Libmpv.set_property_string(MpvHandle, "osc", "no");
            Libmpv.set_property_string(MpvHandle, "force-window", "no");
            Libmpv.set_property_string(MpvHandle, "no-taskbar-progress", "no");
            var err = Libmpv.mpv_initialize(MpvHandle);

            if (err != Libmpv.mpv_error.MPV_ERROR_SUCCESS)
            {
                throw new LibMpvException(err);
            }
            MpvObservables.SetupObservables(MpvHandle);
        }
Example #4
0
        private void WaitForEvent(Libmpv.mpv_event_id eventId)
        {
            while (true)
            {
                var ptr = Libmpv.mpv_wait_event(MpvHandle, -1);

                if (Marshal.PtrToStructure(ptr, typeof(Libmpv.mpv_event)) is Libmpv.mpv_event evt)
                {
                    if (evt.event_id == eventId)
                    {
                        break;
                    }
                }
            }
        }
Example #5
0
        public IEnumerable <MediaTrack> GetTracks()
        {
            var count = Libmpv.get_property_int(MpvHandle, "track-list/count");

            for (var i = 0; i < count; i++)
            {
                var type = Libmpv.get_property_string(MpvHandle, $"track-list/{i}/type");

                if (type == "video")
                {
                    continue;
                }

                yield return(new MediaTrack(type == "sub" ? MediaTrackType.Subtitle : MediaTrackType.Audio,
                                            GetLanguage(Libmpv.get_property_string(MpvHandle, $"track-list/{i}/lang")),
                                            Libmpv.get_property_int(MpvHandle, $"track-list/{i}/id"),
                                            Libmpv.get_property_string(MpvHandle, $"track-list/{i}/title")));
            }
        }
Example #6
0
 public static string GetMessage(this Libmpv.mpv_error err) => ConvertFromUtf8(Libmpv.mpv_error_string(err));
Example #7
0
 public void Close()
 {
     Libmpv.mpv_terminate_destroy(MpvHandle);
     EventTaskCancellationTokenSource?.Cancel();
     EventTask?.Dispose();
 }