Exemple #1
0
        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 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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        private void LoadSong(string path)
        {
            FilgraphManager filterManager = new FilgraphManager();

            filterManager.RenderFile(path);
            this.controller = filterManager as IMediaControl;
            this.position   = filterManager as IMediaPosition;
        }
Exemple #5
0
        public void Open(string audioUri)
        {
            CleanUp();
            //Console.WriteLine(audioUri);
            filgraphManager = new FilgraphManager();
            filgraphManager.RenderFile(audioUri);

            SetPlayerCollaborators();

            mediaControl.Run();
        }
        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);
        }
Exemple #7
0
/*
 * 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;
            }
        }
Exemple #9
0
        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 {}
        }
Exemple #10
0
        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();
            }
        }
        //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();
        }
Exemple #12
0
        /// <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();
        }
Exemple #13
0
        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();
            }
        }
Exemple #14
0
 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);
 }
        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();
        }
Exemple #16
0
    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 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;
            }
        }
Exemple #18
0
        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;

            }
        }
        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;
        }
Exemple #20
0
        public void openFile(string filename)
        {
            CleanUp();

            m_objFilterGraph = new FilgraphManager();
            m_objFilterGraph.RenderFile(filename);

           
            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 = "Preview - [" + filename + "]";
            m_objMediaControl.Run();
            m_objMediaControl.Pause();
            

            UpdateStatusBar();
            UpdateToolBar();
        }
 private void LoadSong(string path)
 {
     FilgraphManager filterManager = new FilgraphManager();
     filterManager.RenderFile(path);
     this.controller = filterManager as IMediaControl;
     this.position = filterManager as IMediaPosition;
 }
        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 = "播放失败!请尝试换个链接或者下载!";
                //}));
            }
        }
        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();
        }
Exemple #24
0
        /// <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;
        }
        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;
        }
        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 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();
        }
Exemple #28
0
        //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;
        }
        private void Video_Load(object sender, EventArgs e)
        {
            try
            {
                CleanUp();

                m_objFilterGraph = new FilgraphManager();
                m_objFilterGraph.RenderFile(Application.StartupPath + @"\video\" + id +".mp4");

                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;

                m_objMediaControl.Run();
                m_CurrentStatus = MediaStatus.Running;

            }
            catch (Exception)
            {

                this.Close();
            }
        }