public static VideoInfo GetVideoInfo(string videoFileName) { var info = new VideoInfo { Success = false }; try { var quartzFilgraphManager = new FilgraphManager(); quartzFilgraphManager.RenderFile(videoFileName); int width; int height; (quartzFilgraphManager as IBasicVideo).GetVideoSize(out width, out height); info.Width = width; info.Height = height; var basicVideo2 = (quartzFilgraphManager as IBasicVideo2); if (basicVideo2.AvgTimePerFrame > 0) { info.FramesPerSecond = 1 / basicVideo2.AvgTimePerFrame; } info.Success = true; var iMediaPosition = (quartzFilgraphManager as IMediaPosition); info.TotalMilliseconds = iMediaPosition.Duration * 1000; info.TotalSeconds = iMediaPosition.Duration; info.TotalFrames = info.TotalSeconds * info.FramesPerSecond; info.VideoCodec = string.Empty; // TODO... get real codec names from quartzFilgraphManager.FilterCollection; Marshal.ReleaseComObject(quartzFilgraphManager); } catch { } return(info); }
private void OpenFile(object sender, RoutedEventArgs e) { OpenFileDialog openFile = new OpenFileDialog(); openFile.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;" + "*.wav;*.mp2;*.mp3|All Files|*.*"; Nullable <bool> result = openFile.ShowDialog(); if (result == true) { FilgraphManager filterGraph = new FilgraphManager(); // This is to show video in a separate control // IMediaControl mc = filterGraph as IMediaControl; IBasicAudio m_objBasicAudio = filterGraph as IBasicAudio; IVideoWindow m_objVideoWindow; try { m_objVideoWindow = filterGraph as IVideoWindow; m_objVideoWindow.Owner = 0; } catch (Exception ex) { m_objVideoWindow = null; } } }
private void ReleaseUnmangedResources() { try { if (_quartzVideo != null) { _quartzVideo.Owner = -1; } } catch { } if (_quartzFilgraphManager != null) { try { _quartzFilgraphManager.Stop(); Marshal.ReleaseComObject(_quartzFilgraphManager); _quartzFilgraphManager = null; } catch { } } _quartzVideo = null; }
private void OpenFile(object sender, RoutedEventArgs e) { OpenFileDialog openFile = new OpenFileDialog(); openFile.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;" + "*.wav;*.mp2;*.mp3|All Files|*.*"; Nullable<bool> result = openFile.ShowDialog(); if (result == true) { FilgraphManager filterGraph = new FilgraphManager(); // This is to show video in a separate control // IMediaControl mc = filterGraph as IMediaControl; IBasicAudio m_objBasicAudio = filterGraph as IBasicAudio; IVideoWindow m_objVideoWindow; try { m_objVideoWindow = filterGraph as IVideoWindow; m_objVideoWindow.Owner = 0; } catch (Exception ex) { m_objVideoWindow = null; } } }
private bool PlayVideo(string path) { CleanUp(); FilterGraph = new FilgraphManager(); FilterGraph.RenderFile(path); BasicAudio = FilterGraph as IBasicAudio; try { VideoWindow = FilterGraph as IVideoWindow; VideoWindow.Owner = (int)panel1.Handle; VideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; VideoWindow.SetWindowPosition(panel1.ClientRectangle.Left, panel1.ClientRectangle.Top, panel1.ClientRectangle.Width, panel1.ClientRectangle.Height); } catch (Exception) { VideoWindow = null; return(false); } MediaEvent = FilterGraph as IMediaEvent; MediaEventEx = FilterGraph as IMediaEventEx; MediaPosition = FilterGraph as IMediaPosition; MediaControl = FilterGraph as IMediaControl; MediaControl.Run(); return(true); }
private void rtbContent_LinkClicked(object sender, LinkClickedEventArgs e) { Regex reg_voice = new Regex(@"(?<=播放语音\().+(?=\))"); Regex reg_video = new Regex(@"(?<=播放视频\().+(?=\))"); if (reg_voice.IsMatch(e.LinkText)) // 语音信息 { FilgraphManager fm = new FilgraphManager(); string msg_id = reg_voice.Match(e.LinkText).Value; string voice_file = m_wx_voices[msg_id]; fm.RenderFile(voice_file); fm.Run(); } else if (reg_video.IsMatch(e.LinkText)) // 视频信息 { FilgraphManager fm = new FilgraphManager(); string msg_id = reg_video.Match(e.LinkText).Value; string video_file = m_wx_videos[msg_id]; fm.RenderFile(video_file); FrmVideo frm_video = new FrmVideo(); frm_video.FM = fm; frm_video.FileName = video_file; frm_video.Show(); } else // 普通超链接 { Process.Start(e.LinkText); } }
private void LoadSong(string path) { FilgraphManager filterManager = new FilgraphManager(); filterManager.RenderFile(path); this.controller = filterManager as IMediaControl; this.position = filterManager as IMediaPosition; }
static void Main() { var graphManager = new FilgraphManager(); #pragma warning disable IDE0059 // Unnecessary assignment of a value var mc = (IMediaControl)graphManager; #pragma warning restore IDE0059 // Unnecessary assignment of a value }
public void Run() { if (!string.IsNullOrWhiteSpace(this.Source)) { if (this.State == MediaStatus.Stopped) { try { filterGraph = new FilgraphManager(); this.filterGraph.RenderFile(this.Source); basicAudio = filterGraph as IBasicAudio; try { videoWindow = filterGraph as IVideoWindow; videoWindow.Owner = (int)this.Handle; videoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; videoWindow.SetWindowPosition(this.ClientRectangle.Left, this.ClientRectangle.Top, this.ClientRectangle.Width, this.ClientRectangle.Height); } catch (Exception) { videoWindow = null; } mediaEvent = filterGraph as IMediaEvent; mediaEventEx = filterGraph as IMediaEventEx; mediaEventEx.SetNotifyWindow((int)base.Handle, WM_GRAPHNOTIFY, 0); mediaPosition = filterGraph as IMediaPosition; mediaControl = filterGraph as IMediaControl; } catch { try { mediaControl.StopWhenReady(); } catch { mediaControl.Stop(); } this.CleanUp(); this.State = MediaStatus.Stopped; throw; } } if (this.State != MediaStatus.Running) { this.mediaControl.Run(); this.State = MediaStatus.Running; } } }
/// <summary> /// 열기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void openMenuItem_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "미디어 파일|*.mpg;*.avi;*.wma;*.wmv;*.mov;*.wav;*.mp2;*.mp3|모든 파일|*.*"; if (DialogResult.OK == openFileDialog.ShowDialog()) { ReleaseResource(); this.filterGraphManager = new FilgraphManager(); this.filterGraphManager.RenderFile(openFileDialog.FileName); this.basicAudio = this.filterGraphManager as IBasicAudio; try { this.videoWindow = this.filterGraphManager as IVideoWindow; this.videoWindow.Owner = (int)this.canvasPanel.Handle; this.videoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; this.videoWindow.SetWindowPosition ( this.canvasPanel.ClientRectangle.Left, this.canvasPanel.ClientRectangle.Top, this.canvasPanel.ClientRectangle.Width, this.canvasPanel.ClientRectangle.Height ); } catch (Exception) { this.videoWindow = null; } this.mediaEvent = this.filterGraphManager as IMediaEvent; this.mediaEventEX = this.filterGraphManager as IMediaEventEx; this.mediaEventEX.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0); this.mediaPosition = this.filterGraphManager as IMediaPosition; this.mediaControl = this.filterGraphManager as IMediaControl; this.Text = "DirectShow를 사용해 동영상 재생하기 - [" + openFileDialog.FileName + "]"; this.mediaControl.Run(); mediaStatus = MediaStatus.RUNNING; UpdateToolBar(); UpdateStatusBar(); } }
public void Play() { // Access the IMediaControl interface. var graphManager = new FilgraphManager(); IMediaControl mc = graphManager; // Specify the file. mc.RenderFile(this.mediaFile); // Start playing the audio asynchronously. mc.Run(); }
//////////////////////////////////////////////////////////////////////////////// Function #region 리소스 해제하기 - ReleaseResource() /// <summary> /// 리소스 해제하기 /// </summary> private void ReleaseResource() { if (this.mediaControl != null) { this.mediaControl.Stop(); } this.mediaStatus = MediaStatus.STOPPED; if (this.mediaEventEX != null) { this.mediaEventEX.SetNotifyWindow(0, 0, 0); } if (this.videoWindow != null) { this.videoWindow.Visible = 0; this.videoWindow.Owner = 0; } if (this.mediaControl != null) { this.mediaControl = null; } if (this.mediaPosition != null) { this.mediaPosition = null; } if (this.mediaEventEX != null) { this.mediaEventEX = null; } if (this.mediaEvent != null) { this.mediaEvent = null; } if (this.videoWindow != null) { this.videoWindow = null; } if (this.basicAudio != null) { this.basicAudio = null; } if (this.filterGraphManager != null) { this.filterGraphManager = null; } }
public static void Main(string[] args) { // Check to see if the user passed in a filename //if (args.Length != 1) //{ // DisplayUsage(); // return; //} //if (args[0] == "/?") //{ // DisplayUsage(); // return; //} string filename = @"C:\Users\Public\Videos\Sample Videos\Wildlife.wmv"; // Check to see if the file exists if (!System.IO.File.Exists(filename)) { Console.WriteLine("File " + filename + " not found."); DisplayUsage(); return; } // Create instance of Quartz // (Calls CoCreateInstance(E436EBB3-524F-11CE-9F53-0020AF0BA770, // NULL, CLSCTX_ALL, IID_IUnknown, &graphManager).): try { FilgraphManager graphManager = new FilgraphManager(); // QueryInterface for the IMediaControl interface: IMediaControl mc = (IMediaControl)graphManager; // Call some methods on a COM interface // Pass in file to RenderFile method on COM object. mc.RenderFile(filename); // Show file. mc.Run(); } catch (Exception ex) { Console.WriteLine("Unexpected COM exception: " + ex.Message); } // Wait for completion. Console.WriteLine("Press Enter to continue."); Console.ReadLine(); }
private void LoadSong(string path) { FilgraphManager filterManager = new FilgraphManager(); filterManager.RenderFile(path); // this.controller = filterManager as IMediaControl; // this.position = filterManager as IMediaPosition; Uri current = new Uri(this.playlist.CurrentSong.Path, UriKind.Relative); this.control.Open(current); }
public void Open(string audioUri) { CleanUp(); //Console.WriteLine(audioUri); filgraphManager = new FilgraphManager(); filgraphManager.RenderFile(audioUri); SetPlayerCollaborators(); mediaControl.Run(); }
private void CleanUp() { if (mediaControl != null) { mediaControl.StopWhenReady(); } mediaControl = null; mediaPosition = null; basicAudio = null; filgraphManager = null; }
/* * int AddToRot(object UnkGraph) * { * IMoniker pMoniker = null; * IRunningObjectTable pROT = null; * * GetRunningObjectTable(0, pROT); * * CreateItemMoniker("!", "MyMoniker", pMoniker); * { * //pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, pUnkGraph, * // pMoniker, pdwRegister); * //pMoniker->Release(); * } * pROT.Release(); * * return 0; * } */ private void menuItem2_Click(object sender, System.EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*"; if (DialogResult.OK == openFileDialog.ShowDialog()) { CleanUp(); //object Unk; m_objFilterGraph = new FilgraphManager(); /* m_objFilterGraph.AddFilter( * "D:\\Expert\\onvif\\axis\\RTSP_source.090603\\RTSP_source.ax", * //"D:\\Expert\\onvif\\axis\\RTSP_source.090603\\RTSP_source.ax", * out Unk); */ m_objFilterGraph.RenderFile(openFileDialog.FileName); m_objBasicAudio = m_objFilterGraph as IBasicAudio; try { m_objVideoWindow = m_objFilterGraph as IVideoWindow; m_objVideoWindow.Owner = (int)panel1.Handle; m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left, panel1.ClientRectangle.Top, panel1.ClientRectangle.Width, panel1.ClientRectangle.Height); } catch (Exception) { m_objVideoWindow = null; } m_objMediaEvent = m_objFilterGraph as IMediaEvent; m_objMediaEventEx = m_objFilterGraph as IMediaEventEx; m_objMediaEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0); m_objMediaPosition = m_objFilterGraph as IMediaPosition; m_objMediaControl = m_objFilterGraph as IMediaControl; this.Text = "DirectShow - [" + openFileDialog.FileName + "]"; m_objMediaControl.Run(); m_CurrentStatus = MediaStatus.Running; UpdateStatusBar(); UpdateToolBar(); } }
public override void Initialize(Control ownerControl, string videoFileName, EventHandler onVideoLoaded, EventHandler onVideoEnded) { const int wsChild = 0x40000000; string ext = System.IO.Path.GetExtension(videoFileName).ToLower(); bool isAudio = ext == ".mp3" || ext == ".wav" || ext == ".wma" || ext == ".ogg" || ext == ".mpa" || ext == ".m4a" || ext == ".ape" || ext == ".aiff" || ext == ".flac" || ext == ".aac" || ext == ".mka"; OnVideoLoaded = onVideoLoaded; OnVideoEnded = onVideoEnded; VideoFileName = videoFileName; _owner = ownerControl; _quartzFilgraphManager = new FilgraphManager(); _quartzFilgraphManager.RenderFile(VideoFileName); if (!isAudio) { _quartzVideo = _quartzFilgraphManager as IVideoWindow; _quartzVideo.Owner = (int)ownerControl.Handle; _quartzVideo.SetWindowPosition(0, 0, ownerControl.Width, ownerControl.Height); _quartzVideo.WindowStyle = wsChild; } //Play(); if (!isAudio) { (_quartzFilgraphManager as IBasicVideo).GetVideoSize(out _sourceWidth, out _sourceHeight); } _owner.Resize += OwnerControlResize; _mediaPosition = (IMediaPosition)_quartzFilgraphManager; if (OnVideoLoaded != null) { _videoLoader = new BackgroundWorker(); _videoLoader.RunWorkerCompleted += VideoLoaderRunWorkerCompleted; _videoLoader.DoWork += VideoLoaderDoWork; _videoLoader.RunWorkerAsync(); } OwnerControlResize(this, null); _videoEndTimer = new Timer { Interval = 500 }; _videoEndTimer.Tick += VideoEndTimerTick; _videoEndTimer.Start(); if (!isAudio) { _quartzVideo.MessageDrain = (int)ownerControl.Handle; } }
private void CleanUp() { if (m_objMediaControl != null) { m_objMediaControl.Stop(); } m_CurrentStatus = MediaStatus.Stopped; if (m_objMediaEventEx != null) { m_objMediaEventEx.SetNotifyWindow(0, 0, 0); } if (m_objVideoWindow != null) { m_objVideoWindow.Visible = 0; m_objVideoWindow.Owner = 0; } if (m_objMediaControl != null) { m_objMediaControl = null; } if (m_objMediaPosition != null) { m_objMediaPosition = null; } if (m_objMediaEventEx != null) { m_objMediaEventEx = null; } if (m_objMediaEvent != null) { m_objMediaEvent = null; } if (m_objVideoWindow != null) { m_objVideoWindow = null; } if (m_objBasicAudio != null) { m_objBasicAudio = null; } if (m_objFilterGraph != null) { m_objFilterGraph = null; } }
//setzt alle DirectShow Sachen auf null private void CleanUp() { if (MediaControl != null) { MediaControl.Stop(); } if (MediaEventEx != null) { MediaEventEx.SetNotifyWindow(0, 0, 0); } if (VideoWindow != null) { VideoWindow.Visible = 0; VideoWindow.Owner = 0; } if (MediaControl != null) { MediaControl = null; } if (MediaPosition != null) { MediaPosition = null; } if (MediaEventEx != null) { MediaEventEx = null; } if (MediaEvent != null) { MediaEvent = null; } if (VideoWindow != null) { VideoWindow = null; } if (BasicAudio != null) { BasicAudio = null; } if (FilterGraph != null) { FilterGraph = null; } }
//TODO Fichier déjà utilisé.... surement par Quartz. Essayer de libérer les ressources de la librairie public void Play(Guid id, byte[] file) { objFilterGraph = new FilgraphManager(); audio = (IBasicAudio) objFilterGraph; //pb d'accès concurrenciel string path = ConfigurationManager.AppSettings["MediaCache"] + id + ".mp3"; File.WriteAllBytes(path, file); objFilterGraph.RenderFile(path); objMediaPosition = objFilterGraph as IMediaPosition; objFilterGraph.Run(); tmProgressionFlux = new Timer(1000) { Enabled = true }; tmProgressionFlux.Elapsed += TmProgressionFluxTick; TimerResume(); }
private void init(string s) //³õʼ²¥·ÅÆ÷ { try { m_objFilterGraph = new FilgraphManager(); m_objFilterGraph.RenderFile(s); m_objBasicAudio = m_objFilterGraph as IBasicAudio; m_objMediaEvent = m_objFilterGraph as IMediaEvent; m_objMediaEventEx = m_objFilterGraph as IMediaEventEx; m_objMediaControl = m_objFilterGraph as IMediaControl; } catch {} }
private void cmdOpen_Click(object sender, EventArgs e) { // Allow the user to choose a file. OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|" + "All Files|*.*"; if (DialogResult.OK == openFileDialog.ShowDialog()) { // Stop the playback for the current movie, if it exists. if (mc != null) { mc.Stop(); } // Load the movie file. FilgraphManager graphManager = new FilgraphManager(); graphManager.RenderFile(openFileDialog.FileName); // Attach the view to a picture box on the form. try { videoWindow = (IVideoWindow)graphManager; videoWindow.Owner = (int)pictureBox1.Handle; videoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; videoWindow.SetWindowPosition( pictureBox1.ClientRectangle.Left, pictureBox1.ClientRectangle.Top, pictureBox1.ClientRectangle.Width, pictureBox1.ClientRectangle.Height); } catch { // An error can occur if the file does not have a video // source (for example, an MP3 file.) // You can ignore this error and still allow playback to // continue (without any visualization). } // Start the playback (asynchronously). mc = (IMediaControl)graphManager; mc.Run(); } }
static void Main(string[] args) { // Check to see if the user passed in a filename: if (args.Length != 1) { DisplayUsage(); return; } if (args[0] == "/?") { DisplayUsage(); return; } string filename = args[0]; // Check to see if the file exists if (!System.IO.File.Exists(filename)) { Console.WriteLine("File " + filename + " not found."); DisplayUsage(); return; } // Create instance of Quartz // (Calls CoCreateInstance(E436EBB3-524F-11CE-9F53-0020AF0BA770, // NULL, CLSCTX_ALL, IID_IUnknown, // &graphManager).): try { FilgraphManager graphManager = new FilgraphManager(); IMediaControl mc = (IMediaControl)graphManager; mc.RenderFile(filename); mc.Run(); } catch (Exception e) { Console.WriteLine("Unexpected COM exception: " + e.Message); } // Wait for completion. Console.WriteLine("Press Enter to continue."); Console.ReadLine(); }
// Methods internal AudioAnimate(string prefix, string localname, string ns, SvgDocument doc) : base(prefix, localname, ns, doc) { this.m_objFilterGraph = null; this.m_objBasicAudio = null; this.m_objMediaEvent = null; this.m_objMediaEventEx = null; this.m_objMediaPosition = null; this.m_objMediaControl = null; this.fillColor = Color.Khaki; this.fileName = string.Empty; this.m_CurrentStatus = MediaStatus.None; this.timer = new Timer(); this.oldtime = 0f; this.timertime = 0f; this.timer.Interval = 100; this.timer.Tick += new EventHandler(this.TimerTick); }
public override void AddedToGraph(FilgraphManager fgm) { IGraphBuilder gb = (IGraphBuilder)fgm; //Add the Blackmagic Decoder filter and connect it. try { bfDecoder = Filter.CreateBaseFilterByName("Blackmagic Design Decoder (DMO)"); gb.AddFilter(bfDecoder, "Blackmagic Design Decoder (DMO)"); IPin decoderInput; bfDecoder.FindPin("in0", out decoderInput); bfDecoder.FindPin("out0", out decoderOutput); captureOutput = GetPin(filter, _PinDirection.PINDIR_OUTPUT, Pin.PIN_CATEGORY_CAPTURE, Guid.Empty, false, 0); gb.Connect(captureOutput, decoderInput); } catch { throw new ApplicationException("Failed to add the BlackMagic Decoder filter to the graph"); } base.AddedToGraph(fgm); }
/// <summary> /// Plays the given mediafile in the internal mediaplayer /// </summary> /// <param name="FilePath">File to play</param> public void ShowMedia(string FilePath) { StopMedia(); Lbl_CurrentMedia.Text = Path.GetFileName(FilePath); m_objFilterGraph = new FilgraphManager(); m_objFilterGraph.RenderFile(FilePath); m_objBasicAudio = m_objFilterGraph as IBasicAudio; try { m_objVideoWindow = m_objFilterGraph as IVideoWindow; m_objVideoWindow.Owner = (int)panel2.Handle; //m_objVideoWindow.Owner = (int)panel1.Handle; m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; m_objVideoWindow.SetWindowPosition(panel2.ClientRectangle.Left, panel2.ClientRectangle.Top, panel2.ClientRectangle.Width, panel2.ClientRectangle.Height); } catch (Exception ex) { Console.WriteLine(ex); m_objVideoWindow = null; } m_objMediaEvent = m_objFilterGraph as IMediaEvent; m_objMediaEventEx = m_objFilterGraph as IMediaEventEx; m_objMediaEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0); m_objMediaPosition = m_objFilterGraph as IMediaPosition; m_objMediaControl = m_objFilterGraph as IMediaControl; m_objMediaControl.Run(); m_CurrentStatus = MediaStatus.Running; UpdateMediaButtons(); //UpdateStatusBar(); //UpdateToolBar(); }
private void cmdOpen_Click(object sender, EventArgs e) { // Allow the user to choose a file. OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*"; if (DialogResult.OK == openFileDialog.ShowDialog()) { // Stop the playback for the current movie, if it exists. if (mc != null) mc.Stop(); mc = null; videoWindow = null; // Load the movie file. FilgraphManager graphManager = new FilgraphManager(); graphManager.RenderFile(openFileDialog.FileName); // Attach the view to a picture box on the form. try { videoWindow = (IVideoWindow)graphManager; videoWindow.Owner = (int)pictureBox1.Handle; videoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; videoWindow.SetWindowPosition(pictureBox1.ClientRectangle.Left, pictureBox1.ClientRectangle.Top, pictureBox1.ClientRectangle.Width, pictureBox1.ClientRectangle.Height); } catch { // An error can occur if the file does not have a vide // source (for example, an MP3 file.) // You can ignore this error and still allow playback to // continue (without any visualization). } // Start the playback (asynchronously). mc = (IMediaControl)graphManager; mc.Run(); } }
public bool SetSource(string FileName) { try { FilterGraph = new FilgraphManager(); object ppUnk = null; FilterGraph.AddSourceFilter(FileName, out ppUnk); FilterGraph.RenderFile(FileName); IFilterInfo Info = (IFilterInfo)ppUnk; TestControl = Info.Filter as ITestControl; BasicAudio = FilterGraph as IBasicAudio; VideoWindow = FilterGraph as IVideoWindow; MediaControl = FilterGraph as IMediaControl; } catch (Exception ex) { Clear(); return(false); } return(true); }
/** * To clean up the FilterGraph and other Objects * */ public void CleanUp() { if (m_objMediaControl != null) m_objMediaControl.Stop(); if (m_objMediaEventEx != null) m_objMediaEventEx.SetNotifyWindow(0, 0, 0); if (m_objVideoWindow != null) { m_objVideoWindow.Visible = 0; m_objVideoWindow.Owner = 0; } if (m_objMediaControl != null) m_objMediaControl = null; if (m_objMediaPosition != null) m_objMediaPosition = null; if (m_objMediaEventEx != null) m_objMediaEventEx = null; if (m_objMediaEvent != null) m_objMediaEvent = null; if (m_objVideoWindow != null) m_objVideoWindow = null; if (m_objBasicAudio != null) m_objBasicAudio = null; if (m_objFilterGraph != null) m_objFilterGraph = null; }
private void vodExplorer_Load(object sender, System.EventArgs e) { //this.WindowState = FormWindowState.Maximized; //this.FormBorderStyle=FormBorderStyle.None; m_objFilterGraph = new FilgraphManager(); m_objFilterGraph.RenderFile(strVodPath); m_objBasicAudio = m_objFilterGraph as IBasicAudio; try { m_objVideoWindow = m_objFilterGraph as IVideoWindow; m_objVideoWindow.Owner = (int)panel1.Handle; m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left, panel1.ClientRectangle.Top, panel1.ClientRectangle.Width, panel1.ClientRectangle.Height); } catch (Exception) { m_objVideoWindow = null; } m_objMediaEvent = m_objFilterGraph as IMediaEvent; m_objMediaEventEx = m_objFilterGraph as IMediaEventEx; m_objMediaEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0); m_objMediaPosition = m_objFilterGraph as IMediaPosition; m_objMediaControl = m_objFilterGraph as IMediaControl; //this.Text = "DirectShow - [" + openFileDialog.FileName + "]"; m_objMediaControl.Run(); }
// 필터그레프 private void FilterGraph(Control hWin, string filename) { this.filterGraphManager = new FilgraphManager(); this.filterGraphManager.RenderFile(filename); this.basicAudio = this.filterGraphManager as DirectShowLib.IBasicAudio; try { this.videoWindow = this.filterGraphManager as IVideoWindow; this.videoWindow.Owner = (int)this.canvasPanel.Handle; this.videoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; this.videoWindow.SetWindowPosition ( this.canvasPanel.ClientRectangle.Left, this.canvasPanel.ClientRectangle.Top, this.canvasPanel.ClientRectangle.Width, this.canvasPanel.ClientRectangle.Height ); } catch (Exception) { this.videoWindow = null; } this.mediaEvent = this.filterGraphManager as IMediaEvent; this.mediaEventEX = this.filterGraphManager as IMediaEventEx; this.mediaEventEX.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0); this.mediaPosition = this.filterGraphManager as IMediaPosition; this.mediaControl = this.filterGraphManager as IMediaControl; basicAudio.put_Volume(this.trackBar1.Value); mediaStatus = MediaStatus.READY; UpdateToolBar(); UpdateStatusBar(); }
public void Load() { GraphBuilder = new FilgraphManager() as IGraphBuilder; MediaControl = GraphBuilder as IMediaControl; MediaSeeking = GraphBuilder as IMediaSeeking; MediaEventEx = GraphBuilder as IMediaEventEx; MediaFilter = GraphBuilder as IMediaFilter; thread = new Tsukikage.Windows.Messaging.MessageThread(true); thread.Invoke(m => { window = new Tsukikage.Windows.Messaging.MessageWindow(); }); const int WM_APP_MEDIA_EVENT = 0x8001; window.MessageHandlers[WM_APP_MEDIA_EVENT] = m => { int ev, p1, p2; while (MediaEventEx.GetEvent(out ev, out p1, out p2, 0) == 0) { if (ev == 0x01 && MediaComplete != null) { MediaComplete(this, EventArgs.Empty); } MediaEventEx.FreeEventParams(ev, p1, p2); } }; MediaEventEx.SetNotifyWindow(window.Handle, WM_APP_MEDIA_EVENT, 0); BuildGraph(path); if (RegisterToROT) { RotEntry = new RunningObjectTableEntry(GraphBuilder, "FilterGraph"); } MediaControl.Stop(); }
public void PlayMovie(Form F, Panel panel, string FileName, ref int RC, ref string ErrMsg) { RC = 1; Single H = 0, W = 0; m_objFilterGraph = new FilgraphManager(); m_objFilterGraph.RenderFile(FileName); m_objBasicAudio = m_objFilterGraph as IBasicAudio; try { m_objVideoWindow = m_objFilterGraph as IVideoWindow; m_objVideoWindow.Owner = (int)panel.Handle; m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; ObjectFitting(true, ref W, ref H, panelOrigWidth, panelOrigHeight, m_objVideoWindow.Width, m_objVideoWindow.Height); panel.Top = panelOrigTop + (panelOrigHeight - (int)H) / 2; panel.Left = panelOrigLeft + (panelOrigWidth - (int)W) / 2; panel.Width = (int)W; panel.Height = (int)H; m_objVideoWindow.SetWindowPosition(panel.ClientRectangle.Left, panel.ClientRectangle.Top, panel.ClientRectangle.Width, panel.ClientRectangle.Height); } catch (Exception e) { m_objVideoWindow = null; RC = 1; ErrMsg = "Unexpedted Error: " + e.Message; } m_objMediaEvent = m_objFilterGraph as IMediaEvent; m_objMediaEventEx = m_objFilterGraph as IMediaEventEx; m_objMediaEventEx.SetNotifyWindow((int)F.Handle, WM_GRAPHNOTIFY, 0); m_objMediaPosition = m_objFilterGraph as IMediaPosition; m_objMediaControl = m_objFilterGraph as IMediaControl; m_objMediaControl.Run(); }
public void Clear() { if (omsdFileName != null) { FileValid = false; System.IO.File.Delete(omsdFileName); } if (MediaControl != null) { MediaControl.Stop(); } if (VideoWindow != null) { VideoWindow.Visible = 0; VideoWindow.Owner = 0; } TestControl = null; MediaControl = null; VideoWindow = null; BasicAudio = null; FilterGraph = null; }
public override void Initialize(Control ownerControl, string videoFileName, EventHandler onVideoLoaded, EventHandler onVideoEnded) { const int wsChild = 0x40000000; var extension = System.IO.Path.GetExtension(videoFileName); if (extension == null) { return; } string ext = extension.ToLower(); bool isAudio = ext == ".mp3" || ext == ".wav" || ext == ".wma" || ext == ".m4a"; OnVideoLoaded = onVideoLoaded; OnVideoEnded = onVideoEnded; VideoFileName = videoFileName; owner = ownerControl; quartzFilgraphManager = new FilgraphManager(); quartzFilgraphManager.RenderFile(VideoFileName); if (!isAudio) { quartzVideo = quartzFilgraphManager as IVideoWindow; if (quartzVideo != null) { quartzVideo.Owner = (int)ownerControl.Handle; quartzVideo.SetWindowPosition(0, 0, ownerControl.Width, ownerControl.Height); quartzVideo.WindowStyle = wsChild; } } //Play(); if (!isAudio) { var basicVideo = quartzFilgraphManager as IBasicVideo; if (basicVideo != null) { basicVideo.GetVideoSize(out sourceWidth, out sourceHeight); } } owner.Resize += OwnerControlResize; mediaPosition = (IMediaPosition)quartzFilgraphManager; if (OnVideoLoaded != null) { videoLoader = new BackgroundWorker(); videoLoader.RunWorkerCompleted += VideoLoaderRunWorkerCompleted; videoLoader.DoWork += VideoLoaderDoWork; videoLoader.RunWorkerAsync(); } OwnerControlResize(this, null); videoEndTimer = new Timer { Interval = 500 }; videoEndTimer.Tick += VideoEndTimerTick; videoEndTimer.Start(); if (isAudio) { return; } if (quartzVideo != null) { quartzVideo.MessageDrain = (int)ownerControl.Handle; } }
/// <summary> /// 清理资源 /// </summary> public void Dispose() { if (m_objMediaControl != null) m_objMediaControl.Stop(); m_currentStatus = MediaStatus.Stopped; if (m_objMediaEventEx != null) m_objMediaEventEx.SetNotifyWindow(0, 0, 0); if (m_objMediaControl != null) m_objMediaControl = null; if (m_objMediaPosition != null) m_objMediaPosition = null; if (m_objMediaEventEx != null) m_objMediaEventEx = null; if (m_objMediaEvent != null) m_objMediaEvent = null; if (m_objBasicAudio != null) m_objBasicAudio = null; //System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objFilterGraph); if (m_objFilterGraph != null) m_objFilterGraph = null; //System.Runtime.InteropServices.Marshal.ReleaseComObject //QuartzTypeLib.FilgraphManagerClass fm = new FilgraphManagerClass(); }
//PLAYER ý yeniden yükleme iþlemi.... public void ReLoad() { if (m_obj_MediaControl != null) { m_obj_MediaControl.Stop(); m_CurrentStatus = MediaStatus.Stopped; } if (m_obj_MediaEventEx != null) m_obj_MediaEventEx.SetNotifyWindow(0, 0, 0); if (m_obj_VideoWindow != null) { m_obj_VideoWindow.Visible = 0; m_obj_VideoWindow.Owner = 0; } if (m_obj_MediaControl != null) m_obj_MediaControl = null; if (m_obj_MediaPosition != null) m_obj_MediaPosition = null; if (m_obj_MediaEventEx != null) m_obj_MediaEventEx = null; if (m_obj_MediaEvent != null) m_obj_MediaEvent = null; if (m_obj_VideoWindow != null) m_obj_VideoWindow = null; if (m_obj_BasicAudio != null) m_obj_BasicAudio = null; if (m_obj_FilterGraph != null) m_obj_FilterGraph = null; if (itemList.Items.Count == 0) { m_CurrentStatus = MediaStatus.None; trackBar2.Enabled = false; trackBar1.Enabled = false; if (videoplaying) playerform.Dispose(); videoplaying = false; m_CurrentStatus = MediaStatus.None; } UpdateToolStrip(); }
public override void Initialize(Control ownerControl, string videoFileName, EventHandler onVideoLoaded, EventHandler onVideoEnded) { const int wsChild = 0x40000000; string ext = System.IO.Path.GetExtension(videoFileName).ToLower(); bool isAudio = ext == ".mp3" || ext == ".wav" || ext == ".wma" || ext == ".ogg" || ext == ".mpa" || ext == ".m4a" || ext == ".ape" || ext == ".aiff" || ext == ".flac" || ext == ".acc" || ext == ".mka"; OnVideoLoaded = onVideoLoaded; OnVideoEnded = onVideoEnded; VideoFileName = videoFileName; _owner = ownerControl; _quartzFilgraphManager = new FilgraphManager(); _quartzFilgraphManager.RenderFile(VideoFileName); if (!isAudio) { _quartzVideo = _quartzFilgraphManager as IVideoWindow; _quartzVideo.Owner = (int)ownerControl.Handle; _quartzVideo.SetWindowPosition(0, 0, ownerControl.Width, ownerControl.Height); _quartzVideo.WindowStyle = wsChild; } //Play(); if (!isAudio) (_quartzFilgraphManager as IBasicVideo).GetVideoSize(out _sourceWidth, out _sourceHeight); _owner.Resize += OwnerControlResize; _mediaPosition = (IMediaPosition)_quartzFilgraphManager; if (OnVideoLoaded != null) { _videoLoader = new BackgroundWorker(); _videoLoader.RunWorkerCompleted += VideoLoaderRunWorkerCompleted; _videoLoader.DoWork += VideoLoaderDoWork; _videoLoader.RunWorkerAsync(); } OwnerControlResize(this, null); _videoEndTimer = new Timer { Interval = 500 }; _videoEndTimer.Tick += VideoEndTimerTick; _videoEndTimer.Start(); if (!isAudio) _quartzVideo.MessageDrain = (int)ownerControl.Handle; }
private void ReleaseUnmangedResources() { try { if (_quartzVideo != null) _quartzVideo.Owner = -1; } catch { } if (_quartzFilgraphManager != null) { try { _quartzFilgraphManager.Stop(); Marshal.ReleaseComObject(_quartzFilgraphManager); _quartzFilgraphManager = null; } catch { } } _quartzVideo = null; }
/// <summary> /// Initializes the device by instantiating the filter, adding it into the filtergraph, /// adding any upstream filters (like crossbars) /// /// If any of these actions fail, the device cleans itself up by calling Dispose. /// </summary> public virtual void AddedToGraph(FilgraphManager fgm) { // Store graph we will be a part of this.fgm = fgm; // Retrieve all pins for this device ArrayList pins = GetPins(filter); outputPins = GetPins(pins, _PinDirection.PINDIR_OUTPUT); inputPins = GetPins(pins, _PinDirection.PINDIR_INPUT); InitializeInputPin(); InitializeOutputPin(); }
//Search Function public bool Process() { bool success = true; String currentDirectory = Environment.CurrentDirectory; //Create recursively a list with all the files complying with the criteria List<FileInfo> videoFileInfos = new List<FileInfo>(); foreach (string fileName in _args.Filenames ) { //Eliminate white spaces var trimmedFileName = fileName.Trim(); var filename = Path.GetFileName( trimmedFileName ); var fileDirectory = Path.GetDirectoryName( trimmedFileName ); if ( String.IsNullOrWhiteSpace( fileDirectory ) ) { fileDirectory = currentDirectory; } videoFileInfos.AddRange( GetFiles( fileDirectory, filename, _args.Recursive ) ); } if ( videoFileInfos.Count == 0 ) { success = false; UpdateStatus( "no files to process" ); } if ( success ) { using ( BaseChapterWriter chapterWriter = _args.ChapterWriterFactory.Create( _args.ChapterFileName ) ) using ( BaseSubtitleWriter subtitleWriter = _args.SubtitleWriterFactory.Create( _args.SubtitleFileName ) ) { bool addDefaultPrefix = !String.IsNullOrEmpty( _args.SubtitlePrefixFilename ) && !_args.SubtitlePrefixFilename.Equals( "auto", StringComparison.OrdinalIgnoreCase ); if ( addDefaultPrefix ) { FileInfo SubtitlePrefix = new FileInfo( _args.SubtitlePrefixFilename ); StreamReader SubtitlePrefixFS = SubtitlePrefix.OpenText(); subtitleWriter.Prefix = SubtitlePrefixFS.ReadToEnd(); SubtitlePrefixFS.Close(); } int fileCount = 0; int subCount = 1; bool empty = true; FrameInfo totalFrameInfo = new FrameInfo(); totalFrameInfo.FrameRate = _args.FrameRate; totalFrameInfo.Duration = 0; string previousFormattedFilename = null; // Sorts the values of the list var orderedVideoFileInfos = videoFileInfos.OrderBy( videoFileInfo => videoFileInfo.FullName ); foreach ( FileInfo videoFileInfo in orderedVideoFileInfos ) { try { UpdateStatus( $"Processing '{videoFileInfo.Name}'" ); FilgraphManager filterGraphManager = null; IMediaPosition mediaPosition = null; filterGraphManager = new FilgraphManager(); filterGraphManager.RenderFile( videoFileInfo.FullName ); // Find file's frame rate double fileFrameRate = 1 / ((IBasicVideo)filterGraphManager).AvgTimePerFrame; mediaPosition = filterGraphManager as IMediaPosition; string formattedFilename = Path.GetFileNameWithoutExtension( videoFileInfo.Name ); if ( _args.Scenalyzer ) { formattedFilename = ScenalyzerFormat( formattedFilename ); } else { string formattedFileDateTime = formattedFilename; if ( formattedFileDateTime.Contains( "(" ) ) { formattedFileDateTime = formattedFileDateTime.Substring( 0, formattedFileDateTime.IndexOf( "(" ) ); } formattedFileDateTime = formattedFileDateTime.Replace( ".", ":" ); DateTime fileDateTime; if ( DateTime.TryParse( formattedFileDateTime, out fileDateTime ) ) { formattedFilename = FormatDateTime( fileDateTime ); } } fileCount++; FrameInfo Start = new FrameInfo(); Start.FrameRate = fileFrameRate; Start.Duration = totalFrameInfo.Duration; Start.Duration += SECONDS_DELAY_BEFORE_SUBTITLE_DISPLAY; FrameInfo End = new FrameInfo(); End.FrameRate = fileFrameRate; End.Duration = Start.Duration + _args.SubDuration; bool writeMarkers = (_args.IncludeDuplicates || previousFormattedFilename != formattedFilename); if ( writeMarkers ) { chapterWriter.WriteChapter( totalFrameInfo ); UpdateStatus( $"Writing chapter at {totalFrameInfo.Duration} seconds" ); } else { UpdateStatus( "Skipped" ); } totalFrameInfo.Duration += mediaPosition.Duration; if ( writeMarkers ) { if ( End.Duration > totalFrameInfo.Duration ) { End.Duration = totalFrameInfo.Duration - (1 / fileFrameRate); } subtitleWriter.WriteSubtitle( formattedFilename, subCount, Start, End ); subCount++; UpdateStatus( $"Writing subtitle {formattedFilename} at {Start.Duration:#.##} to {End.Duration:#.##}" ); } previousFormattedFilename = formattedFilename; filterGraphManager.Stop(); empty = false; if ( mediaPosition != null ) { mediaPosition = null; } if ( filterGraphManager != null ) { Marshal.FinalReleaseComObject( filterGraphManager ); filterGraphManager = null; } } catch ( SecurityException ex ) { UpdateStatus( $"File, '{videoFileInfo.FullName}' was unable to be opened due to a security exception: {ex.Message}" ); } catch ( FileNotFoundException ) { UpdateStatus( $"File, '{videoFileInfo.FullName}' was not found" ); } } totalFrameInfo.Duration -= .2; chapterWriter.WriteChapter( totalFrameInfo ); if ( empty == true ) { success = false; UpdateStatus( "No matches found!" ); } else { UpdateStatus( $"Processed {fileCount} Files!" ); } } } return success; }
public override void AddedToGraph(FilgraphManager fgm) { base.AddedToGraph (fgm); // Summary of a comment from MSDN // The recommended order of operations for all of the audio codecs // is to set the output type before you set the input type. pcMTs = Pin.GetMediaTypes(OutputPin); }
public virtual void Dispose() { filter = null; fgm = null; inputPin = null; outputPin = null; ClearCollections(); }
public override void AddedToGraph(FilgraphManager fgm) { base.AddedToGraph(fgm); iVfwCap = filter as IAMVfwCaptureDialogs; #region IAMAnalogVideoDecoder iAVD = filter as IAMAnalogVideoDecoder; if(iAVD != null) { int atvf; iAVD.get_AvailableTVFormats(out atvf); if(atvf != (int)tagAnalogVideoStandard.AnalogVideo_None) { ArrayList videoStandards = new ArrayList(); foreach(tagAnalogVideoStandard avs in Enum.GetValues(typeof(tagAnalogVideoStandard))) { if((atvf & (int)avs) == (int)avs) { videoStandards.Add(avs); } } this.videoStandards = new tagAnalogVideoStandard[videoStandards.Count]; videoStandards.CopyTo(0, this.videoStandards, 0, videoStandards.Count); } } #endregion IAMAnalogVideoDecoder }
/// <summary> /// A virtual method that is called once the filter is in a graph /// Allows the filter to configure itself. /// </summary> public override void AddedToGraph(FilgraphManager fgm) { base.AddedToGraph(fgm); // Add Crossbar filter or other filters upstream of this filter BuildUpstreamGraph(); }
public void OpenFileFunc(int filedex) { fileIndex = filedex; listoffilenames.SelectedIndex = fileIndex; object sender = new object(); EventArgs er = new EventArgs(); listoffilenames_SelectedIndexChanged(sender, er); ReLoad(); itemList.Refresh(); string openedfile = this.listoffilenames.Items[fileIndex].ToString(); m_obj_FilterGraph = new FilgraphManager(); try { m_obj_FilterGraph.RenderFile(openedfile); } catch (Exception) { MessageBox.Show("Please choose a valid file.\n Check the file path.\n File path could be changed."); return; } try { m_obj_BasicAudio = m_obj_FilterGraph as IBasicAudio; trackBar1.Value = volumeValue; m_obj_BasicAudio.Volume = trackBar1.Value; if (mute) { volumeValue = -10000; trackBar1.Value = volumeValue; m_obj_BasicAudio.Volume = trackBar1.Value; } } catch { } try { if (!newPlayerIsCreated) { playerform = new player(itemList, listoffilenames, fileIndex, filename); newPlayerIsCreated = true; playerform.Location = new Point(playerformLocationX, playerformLocationY); } m_obj_VideoWindow = m_obj_FilterGraph as IVideoWindow; m_obj_VideoWindow.Owner = (int)playerform.Handle; m_obj_VideoWindow.WindowStyle = WS_CHILD; videoplaying = true; m_obj_VideoWindow.SetWindowPosition(playerform.ClientRectangle.Left, playerform.ClientRectangle.Top, playerform.ClientRectangle.Right, playerform.ClientRectangle.Bottom); } catch (Exception) { m_obj_VideoWindow = null; videoplaying = false; } if (videoplaying) { trackBar2.Enabled = true; trackBar1.Enabled = true; if (fullscreen) { if (playerformactivatedonce == 0) playerform.Show(); fullscreen = false; fullscreenfunc(); } else { if (playerformactivatedonce == 0) playerform.Show(); } playerform.Activate(); } else { trackBar2.Enabled = true; trackBar1.Enabled = true; playerformHeight = playerform.Height; playerformWidth = playerform.Width; playerformLocationX = playerform.Location.X; playerformLocationY = playerform.Location.Y; playerform.Dispose(); newPlayerIsCreated = false; } running = true; m_obj_MediaEvent = m_obj_FilterGraph as IMediaEvent; m_obj_MediaEventEx = m_obj_FilterGraph as IMediaEventEx; m_obj_MediaEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0); m_obj_MediaPosition = m_obj_FilterGraph as IMediaPosition; m_obj_MediaControl = m_obj_FilterGraph as IMediaControl; trackBar2.Maximum = (int)m_obj_MediaPosition.Duration; trackBar2.Minimum = 0; trackBar2.Value = (int)m_obj_MediaPosition.CurrentPosition; m_obj_MediaControl.Run(); m_CurrentStatus = MediaStatus.Running; try { if (searchform != null) searchform.listBox1.SelectedIndex = itemList.SelectedIndex; } catch { } if (isHidden) openModifyWindow(); string[] newfilenamearray = listoffilenames.Items[fileIndex].ToString().Split('\\'); string newfilename = newfilenamearray[newfilenamearray.Length - 1].ToString(); if(newfilename.Length>30) filename.Text = newfilename.Substring(0,29) + " "; else filename.Text = newfilename+ " "; this.Refresh(); UpdateToolStrip(); }
/// <summary> /// 初始化播放 /// </summary> /// <param name="fileName">文件名称(全路径)</param> public void Open(string fileName) { m_objFilterGraph = new FilgraphManager(); m_objFilterGraph.RenderFile(fileName); m_objBasicAudio = m_objFilterGraph as IBasicAudio; m_objMediaEvent = m_objFilterGraph as IMediaEvent; m_objMediaEventEx = m_objFilterGraph as IMediaEventEx; m_objMediaPosition = m_objFilterGraph as IMediaPosition; m_objMediaControl = m_objFilterGraph as IMediaControl; }
static void Main(string[] args) { var graphManager = new FilgraphManager(); var mc = (IMediaControl)graphManager; }
public void Load() { GraphBuilder = new FilgraphManager() as IGraphBuilder; MediaControl = GraphBuilder as IMediaControl; MediaSeeking = GraphBuilder as IMediaSeeking; MediaEventEx = GraphBuilder as IMediaEventEx; MediaFilter = GraphBuilder as IMediaFilter; thread = new Tsukikage.Windows.Messaging.MessageThread(true); thread.Invoke(m => { window = new Tsukikage.Windows.Messaging.MessageWindow(); }); const int WM_APP_MEDIA_EVENT = 0x8001; window.MessageHandlers[WM_APP_MEDIA_EVENT] = m => { int ev, p1, p2; while (MediaEventEx.GetEvent(out ev, out p1, out p2, 0) == 0) { if (ev == 0x01 && MediaComplete != null) MediaComplete(this, EventArgs.Empty); MediaEventEx.FreeEventParams(ev, p1, p2); } }; MediaEventEx.SetNotifyWindow(window.Handle, WM_APP_MEDIA_EVENT, 0); BuildGraph(path); if (RegisterToROT) RotEntry = new RunningObjectTableEntry(GraphBuilder, "FilterGraph"); MediaControl.Stop(); }
private void MediaPreviewer_Load(object sender, EventArgs e) { statusBarPanel1.Text = "Buffering !! Please Wait"; CleanUp(); Console.WriteLine("download finished"); m_objFilterGraph = new FilgraphManager(); try { m_objFilterGraph.RenderFile(fileName); } catch (Exception ex) { return; } m_objBasicAudio = m_objFilterGraph as IBasicAudio; try { m_objVideoWindow = m_objFilterGraph as IVideoWindow; m_objVideoWindow.Owner = (int) panel1.Handle; m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left, panel1.ClientRectangle.Top, panel1.ClientRectangle.Width, panel1.ClientRectangle.Height); } catch (Exception) { m_objVideoWindow = null; } m_objMediaEvent = m_objFilterGraph as IMediaEvent; m_objMediaEventEx = m_objFilterGraph as IMediaEventEx; m_objMediaEventEx.SetNotifyWindow((int) this.Handle,WM_GRAPHNOTIFY, 0); m_objMediaPosition = m_objFilterGraph as IMediaPosition; m_objMediaControl = m_objFilterGraph as IMediaControl; this.Text = "SMART MediaPreviewer"; m_objMediaControl.Run(); m_CurrentStatus = MediaStatus.Running; UpdateStatusBar(); UpdateToolBar(); }
public static VideoInfo GetVideoInfo(string videoFileName) { var info = new VideoInfo { Success = false }; try { var quartzFilgraphManager = new FilgraphManager(); quartzFilgraphManager.RenderFile(videoFileName); int width; int height; (quartzFilgraphManager as IBasicVideo).GetVideoSize(out width, out height); info.Width = width; info.Height = height; var basicVideo2 = (quartzFilgraphManager as IBasicVideo2); if (basicVideo2.AvgTimePerFrame > 0) info.FramesPerSecond = 1 / basicVideo2.AvgTimePerFrame; info.Success = true; var iMediaPosition = (quartzFilgraphManager as IMediaPosition); info.TotalMilliseconds = iMediaPosition.Duration * 1000; info.TotalSeconds = iMediaPosition.Duration; info.TotalFrames = info.TotalSeconds * info.FramesPerSecond; info.VideoCodec = string.Empty; // TODO: Get real codec names from quartzFilgraphManager.FilterCollection; Marshal.ReleaseComObject(quartzFilgraphManager); } catch { } return info; }
private void openMedia() { openFileDialog1.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*"; if (DialogResult.OK == openFileDialog1.ShowDialog()) { CleanUp(); m_objFilterGraph = new FilgraphManager(); m_objFilterGraph.RenderFile(openFileDialog1.FileName); m_objBasicAudio = m_objFilterGraph as IBasicAudio; try { m_objVideoWindow = m_objFilterGraph as IVideoWindow; m_objVideoWindow.Owner = (int)panel1.Handle; m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left, panel1.ClientRectangle.Top, panel1.ClientRectangle.Width, panel1.ClientRectangle.Height); } catch(Exception) { m_objVideoWindow = null; } m_objMediaEvent = m_objFilterGraph as IMediaEvent; m_objMediaEventEx = m_objFilterGraph as IMediaEventEx; m_objMediaEventEx.SetNotifyWindow((int) this.Handle, WM_GRAPHNOTIFY, 0); m_objMediaPosition = m_objFilterGraph as IMediaPosition; m_objMediaControl = m_objFilterGraph as IMediaControl; this.Text = "Whistle- " + openFileDialog1.FileName + "]"; m_objMediaControl.Run(); m_CurrentStatus = MediaStatus.Running; } }
public void PlayeMusic(string url) { try { if (myMediaControl != null) { myMediaControl.Stop(); } //InitPlayer(); myFilterGraph = new FilgraphManager(); //PublicInterFace.LogErro(url); myFilterGraph.RenderFile(url); myBasicAudio = myFilterGraph as IBasicAudio; myMediaEvent = myFilterGraph as IMediaEvent; myMediaPosition = myFilterGraph as IMediaPosition; myMediaControl = myFilterGraph as IMediaControl; myBasicAudio.Volume = 100; //int ai = myBasicAudio.Volume; myMediaControl.Run(); //IsPlay = true; //BaseInovke(new MethodInvoker(delegate() //{ // playerControl.StratAnti(); // playTimer.Start(); //})); } catch (Exception ex) { //PublicInterFace.LogErro("发生异常:\r\n" + ex.Message + "\r\n" + ex.StackTrace); //BaseInovke(new MethodInvoker(delegate() //{ // playTimer.Stop(); // playerControl.StopAnti(); // IsPlay = false; // nowPlayMusic.Text = "播放失败!请尝试换个链接或者下载!"; //})); } }
private void CleanUp() { base.Parent.Focus(); if (mediaControl != null) { mediaControl.Stop(); } this.State = MediaStatus.Stopped; if (mediaEventEx != null) { mediaEventEx.SetNotifyWindow(0, 0, 0); } if (videoWindow != null) { videoWindow.Visible = 0; //int oldOwner = videoWindow.Owner; //videoWindow.Owner = 0; //Control.FromHandle((IntPtr)oldOwner).Focus(); } if (mediaControl != null) { Marshal.ReleaseComObject(mediaControl); } mediaControl = null; if (mediaPosition != null) { Marshal.ReleaseComObject(mediaPosition); } mediaPosition = null; if (mediaEventEx != null) { Marshal.ReleaseComObject(mediaEventEx); } mediaEventEx = null; if (mediaEvent != null) { Marshal.ReleaseComObject(mediaEvent); } mediaEvent = null; if (videoWindow != null) { Marshal.ReleaseComObject(videoWindow); } videoWindow = null; if (basicAudio != null) { Marshal.ReleaseComObject(basicAudio); } basicAudio = null; if (filterGraph != null) { Marshal.ReleaseComObject(filterGraph); } filterGraph = null; //if (mediaControl != null) mediaControl = null; //if (mediaPosition != null) mediaPosition = null; //if (mediaEventEx != null) mediaEventEx = null; //if (mediaEvent != null) mediaEvent = null; //if (videoWindow != null) videoWindow = null; //if (basicAudio != null) basicAudio = null; //if (filterGraph != null) filterGraph = null; }