public void RebuildPlayer() { if (VlcMediaPlayer == null) { throw new InvalidOperationException("VlcPlayer is not initialize."); } Stop(); var newPlayer = Vlc.CreateMediaPlayer(); newPlayer.AudioOutputChannel = VlcMediaPlayer.AudioOutputChannel; newPlayer.Brightness = VlcMediaPlayer.Brightness; newPlayer.Chapter = VlcMediaPlayer.Chapter; newPlayer.Contrast = VlcMediaPlayer.Contrast; newPlayer.Gamma = VlcMediaPlayer.Gamma; newPlayer.Hue = VlcMediaPlayer.Hue; //newPlayer.IsAdjustEnable = VlcMediaPlayer.IsAdjustEnable; newPlayer.IsMute = VlcMediaPlayer.IsMute; newPlayer.Rate = VlcMediaPlayer.Rate; newPlayer.Saturation = VlcMediaPlayer.Saturation; newPlayer.Scale = VlcMediaPlayer.Scale; newPlayer.Subtitle = VlcMediaPlayer.Subtitle; newPlayer.SubtitleDelay = VlcMediaPlayer.SubtitleDelay; newPlayer.Volume = VlcMediaPlayer.Volume; if (AudioEqualizer != null) { newPlayer.SetEqualizer(AudioEqualizer); } AttachPlayer(newPlayer); }
public async Task <VideoAudioInfo> Execute(Stream thumbnailStream) { ThumbnailStream = thumbnailStream; LibVlcManager.LoadLibVlc(AppDomain.CurrentDomain.BaseDirectory + @"..\..\libvlc"); Vlc vlc = new Vlc(new[] { "-I", "dummy", "--ignore-config", "--no-video-title" }); Console.WriteLine($"LibVlcManager: {LibVlcManager.GetVersion()}s"); mediaPlayer = vlc.CreateMediaPlayer(); mediaPlayer.SetVideoDecodeCallback(LockCB, unLockCB, DisplayCB, IntPtr.Zero); mediaPlayer.SetVideoFormatCallback(VideoFormatCallback, VideoCleanupCallback); mediaPlayer.Playing += MediaPlayer_Playing; mediaPlayer.Media = vlc.CreateMediaFromLocation(FilePath); await Task.Run(() => { mediaPlayer.Play(); mediaPlayer.IsMute = true; Stopwatch s = new Stopwatch(); s.Start(); while (waiting) { Thread.Sleep(100); } s.Stop(); TimeSpan sec = new TimeSpan(s.ElapsedTicks); Console.WriteLine(sec.ToString()); mediaPlayer.Dispose(); vlc.Dispose(); }); _VideoAudioInfo.Resolution = JsonConvert.SerializeObject(_VideoResolution); //_VideoAudioInfo.Thumbnail = ThumbnailStream; return(_VideoAudioInfo); }
public void RebuildPlayer() { ThrowIfNotInitialize(); Stop(); var newPlayer = Vlc.CreateMediaPlayer(); newPlayer.AudioOutputChannel = VlcMediaPlayer.AudioOutputChannel; newPlayer.Brightness = VlcMediaPlayer.Brightness; newPlayer.Chapter = VlcMediaPlayer.Chapter; newPlayer.Contrast = VlcMediaPlayer.Contrast; newPlayer.Gamma = VlcMediaPlayer.Gamma; newPlayer.Hue = VlcMediaPlayer.Hue; //newPlayer.IsAdjustEnable = VlcMediaPlayer.IsAdjustEnable; newPlayer.IsMute = VlcMediaPlayer.IsMute; newPlayer.Rate = VlcMediaPlayer.Rate; newPlayer.Saturation = VlcMediaPlayer.Saturation; newPlayer.Scale = VlcMediaPlayer.Scale; newPlayer.Subtitle = VlcMediaPlayer.Subtitle; newPlayer.SubtitleDelay = VlcMediaPlayer.SubtitleDelay; newPlayer.Volume = VlcMediaPlayer.Volume; if (AudioEqualizer != null) { newPlayer.SetEqualizer(AudioEqualizer); } AttachPlayer(newPlayer); }
/// <summary> /// Initialize VLC player with path of LibVlc and options. /// </summary> /// <param name="libVlcPath"></param> /// <param name="libVlcOption"></param> public void Initialize(String libVlcPath, params String[] libVlcOption) { if (!ApiManager.IsInitialized) { ApiManager.Initialize(libVlcPath, libVlcOption); } switch (CreateMode) { case PlayerCreateMode.NewVlcInstance: var vlc = new Vlc(libVlcOption); VlcMediaPlayer = vlc.CreateMediaPlayer(); ApiManager.Vlcs.Add(vlc); break; case PlayerCreateMode.Default: default: VlcMediaPlayer = ApiManager.DefaultVlc.CreateMediaPlayer(); break; } if (VlcMediaPlayer != null) { VlcMediaPlayer.PositionChanged += VlcMediaPlayerPositionChanged; VlcMediaPlayer.TimeChanged += VlcMediaPlayerTimeChanged; VlcMediaPlayer.Playing += VlcMediaPlayerStateChanged; VlcMediaPlayer.Paused += VlcMediaPlayerStateChanged; VlcMediaPlayer.Stoped += VlcMediaPlayerStateChanged; VlcMediaPlayer.Opening += VlcMediaPlayerStateChanged; VlcMediaPlayer.Buffering += VlcMediaPlayerStateChanged; VlcMediaPlayer.EndReached += VlcMediaPlayerStateChanged; VlcMediaPlayer.SeekableChanged += VlcMediaPlayerSeekableChanged; VlcMediaPlayer.LengthChanged += VlcMediaPlayerLengthChanged; _lockCallback = VideoLockCallback; _unlockCallback = VideoUnlockCallback; _displayCallback = VideoDisplayCallback; _formatCallback = VideoFormatCallback; _cleanupCallback = VideoCleanupCallback; //_audioSetupCallback = AudioFormatSetupCallback; //_audioCleanupCallback = AudioFormatCleanupCallback; //_audioPlayCallback = AudioPlayCallback; //_audioPauseCallback = AudioPauseCallback; //_audioResumeCallback = AudioResumeCallback; //_audioFlushCallback = AudioFlushCallback; //_audioDrainCallback = AudioDrainCallback; //_audioSetVolumeCallback = AudioSetVolumeCallback; _lockCallbackHandle = GCHandle.Alloc(_lockCallback); _unlockCallbackHandle = GCHandle.Alloc(_unlockCallback); _displayCallbackHandle = GCHandle.Alloc(_displayCallback); _formatCallbackHandle = GCHandle.Alloc(_formatCallback); _cleanupCallbackHandle = GCHandle.Alloc(_cleanupCallback); //_audioSetupCallbackHandle = GCHandle.Alloc(_audioSetupCallback); //_audioCleanupCallbackHandle = GCHandle.Alloc(_audioCleanupCallback); //_audioPlayCallbackHandle = GCHandle.Alloc(_audioPlayCallback); //_audioPauseCallbackHandle = GCHandle.Alloc(_audioPauseCallback); //_audioResumeCallbackHandle = GCHandle.Alloc(_audioResumeCallback); //_audioFlushCallbackHandle = GCHandle.Alloc(_audioFlushCallback); //_audioDrainCallbackHandle = GCHandle.Alloc(_audioDrainCallback); //_audioSetVolumeCallbackHandle = GCHandle.Alloc(_audioSetVolumeCallback); VlcMediaPlayer.SetVideoDecodeCallback(_lockCallback, _unlockCallback, _displayCallback, IntPtr.Zero); VlcMediaPlayer.SetVideoFormatCallback(_formatCallback, _cleanupCallback); //VlcMediaPlayer.SetAudioCallback(_audioPlayCallback, _audioPauseCallback, _audioResumeCallback, _audioFlushCallback, _audioDrainCallback); //VlcMediaPlayer.SetAudioFormatCallback(_audioSetupCallback, _audioCleanupCallback); //VlcMediaPlayer.SetAudioVolumeCallback(_audioSetVolumeCallback); } }
/// <summary> /// Initialize VLC player with path of LibVlc and options. /// </summary> /// <param name="libVlcPath"></param> /// <param name="libVlcOption"></param> public void Initialize(string libVlcPath, params string[] libVlcOption) { if (!ApiManager.IsInitialized) { ApiManager.Initialize(libVlcPath, libVlcOption); } if (VlcMediaPlayer != null) { throw new InvalidOperationException("VlcPlayer is been initialized."); } switch (CreateMode) { case PlayerCreateMode.NewVlcInstance: Vlc = new Vlc(libVlcOption); ApiManager.Vlcs.Add(Vlc); break; case PlayerCreateMode.Default: default: Vlc = ApiManager.DefaultVlc; break; } VlcMediaPlayer player = Vlc.CreateMediaPlayer(); _lockCallback = VideoLockCallback; _unlockCallback = VideoUnlockCallback; _displayCallback = VideoDisplayCallback; _formatCallback = VideoFormatCallback; _cleanupCallback = VideoCleanupCallback; //_audioSetupCallback = AudioFormatSetupCallback; //_audioCleanupCallback = AudioFormatCleanupCallback; //_audioPlayCallback = AudioPlayCallback; //_audioPauseCallback = AudioPauseCallback; //_audioResumeCallback = AudioResumeCallback; //_audioFlushCallback = AudioFlushCallback; //_audioDrainCallback = AudioDrainCallback; //_audioSetVolumeCallback = AudioSetVolumeCallback; _lockCallbackHandle = GCHandle.Alloc(_lockCallback); _unlockCallbackHandle = GCHandle.Alloc(_unlockCallback); _displayCallbackHandle = GCHandle.Alloc(_displayCallback); _formatCallbackHandle = GCHandle.Alloc(_formatCallback); _cleanupCallbackHandle = GCHandle.Alloc(_cleanupCallback); //_audioSetupCallbackHandle = GCHandle.Alloc(_audioSetupCallback); //_audioCleanupCallbackHandle = GCHandle.Alloc(_audioCleanupCallback); //_audioPlayCallbackHandle = GCHandle.Alloc(_audioPlayCallback); //_audioPauseCallbackHandle = GCHandle.Alloc(_audioPauseCallback); //_audioResumeCallbackHandle = GCHandle.Alloc(_audioResumeCallback); //_audioFlushCallbackHandle = GCHandle.Alloc(_audioFlushCallback); //_audioDrainCallbackHandle = GCHandle.Alloc(_audioDrainCallback); //_audioSetVolumeCallbackHandle = GCHandle.Alloc(_audioSetVolumeCallback); if (player == null) { throw new Exception("Vlc media player initialize fail."); } AttachPlayer(player); }