Ejemplo n.º 1
0
 public void OnMediaPlayerMuted()
 {
     Muted?.Invoke(this, new EventArgs());
 }
Ejemplo n.º 2
0
        public VLCMediaPlayer(InputData inputData, ILogger <VLCMediaPlayer> logger)
        {
            this.logger = logger;
            Core.Initialize();
            localFileStreamClient = new Client();
            if (inputData.AttachDebugger)
            {
                vlcArguments.Add("--verbose=2");
            }
            else
            {
                vlcArguments.Add("--verbose=0");
            }

            library      = new LibVLC(vlcArguments.ToArray());
            library.Log += Library_Log;
            mediaPlayer  = new LibVLCSharp.Shared.MediaPlayer(library)
            {
                Hwnd                   = new IntPtr(inputData.Handle),
                EnableKeyInput         = false,
                EnableMouseInput       = false,
                EnableHardwareDecoding = true,
            };
            mediaPlayer.PositionChanged += MediaPlayer_PositionChanged;
            mediaPlayer.EndReached      += (sender, args) =>
            {
                EndReached?.Invoke(this, args);
            };
            mediaPlayer.TimeChanged += (sender, args) =>
            {
                time = args.Time;
                TimeChanged?.Invoke(this, args.Time);

                if (aspectRationSet || mediaPlayer.VideoTrack == -1)
                {
                    return;
                }

                aspectRationSet = true;

                uint  x           = 0;
                uint  y           = 0;
                float aspectRatio = 1;

                if (!mediaPlayer.Size(0, ref x, ref y))
                {
                    return;
                }

                var videoTrack  = mediaPlayer.Media.Tracks.FirstOrDefault(track => track.TrackType == TrackType.Video);
                var orientation = videoTrack.Data.Video.Orientation;

                if (IsFlipped(orientation))
                {
                    aspectRatio = (float)y / x;
                }
                else
                {
                    aspectRatio = (float)x / y;
                }

                if (videoTrack.Data.Video.SarDen != 0)
                {
                    aspectRatio *= (float)videoTrack.Data.Video.SarNum / videoTrack.Data.Video.SarDen;
                }

                VideoInfoChanged?.Invoke(this, new VideoInfo
                {
                    VideoOrientation = orientation.ToString(),
                    AspectRatio      = aspectRatio
                });
            };

            mediaPlayer.LengthChanged += (sender, args) => { if (args.Length > 0)
                                                             {
                                                                 LengthChanged?.Invoke(this, args);
                                                             }
            };
            mediaPlayer.Playing       += (sender, args) => Playing?.Invoke(this, args);
            mediaPlayer.Paused        += (sender, args) => Paused?.Invoke(this, args);
            mediaPlayer.VolumeChanged += (sender, args) => VolumeChanged?.Invoke(this, args);
            mediaPlayer.Unmuted       += (sender, args) => Unmuted?.Invoke(this, args);
            mediaPlayer.Muted         += (sender, args) => Muted?.Invoke(this, args);
        }