CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2012
    Posts
    17

    need help regarding event

    i've come across trouble again this time.

    my problem :
    Code:
     
    i want to make a Movie Player using Micorost.directx.audiovideoplayback.dll
    whats make it trouble is => i want to double click to make it fullscreen.. or i can say do an event.
    for now i place my audiovideoplayback Video in a panel.
    but when i do double click even on the panel, it wont work..
    so i was wondering if there any way to make a panel can be double clicked even if a component covered by other component.

    i guess word alone wont help
    so here the code

    this was made 100% pure coding. except the timer. i dragdrop it
    the timer only used to make the seekbar to follow the following position/max position of video

    why i use directx instead of wmplib?
    because directx can play all type of video while wmplib cant.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    // take on add reference -> browse [C:/windows/assembly/gac/microsoft.directx.audiovideoplayback/audiovideoplayback.dll]
    using Microsoft.DirectX.AudioVideoPlayback;
    
    
    namespace DvMoviePlayer
    {
        public partial class Form1 : Form
        {
            /*
             * INDEX
             * Form Load                DMP001
             * InitializeRestComponent  DMP002
             * autoResize               DMP003
             * createNewVideo           DMP004
             * videoFrame_dragDrop      DMP005
             * videoFrame_dragEnter     DMP006
             * Form1_Resize             DMP007
             * timer1_Tick              DMP008
             */
            /*
            private void test() 
            {
                OpenFileDialog result = new OpenFileDialog();
                result.Filter = "Video Files | *.avi;*.flv;*.mp4;*.wmv";
                result.Multiselect = false;
                result.ShowDialog();
                createNewVideo(result.FileName);
            }
            */
            public Form1()
            {
                InitializeComponent();
                InitializeRestComponent();
            }
            private Panel videoFrame = new Panel();
            private Video video;
            private TrackBar seek_bar = new TrackBar();
            private Label duration = new Label();
    
            private void Form1_Load(object sender, EventArgs e)
            {//DMP001
                
            }
            private void InitializeRestComponent()
            {//DMP002
                autoResize();
                videoFrame.BackColor = Color.Black;
                videoFrame.BorderStyle = BorderStyle.Fixed3D;
                videoFrame.AllowDrop = true;
                videoFrame.DragDrop += new DragEventHandler(this.videoFrame_dragDrop);
                videoFrame.DragEnter += new DragEventHandler(this.videoFrame_dragEnter);
                videoFrame.DoubleClick += new EventHandler(this.videoFrame_doubleClick);
                this.Controls.Add(videoFrame);
                seek_bar.LargeChange = 0;
                seek_bar.SmallChange = 0;
                seek_bar.TickStyle = TickStyle.Both;
                seek_bar.TabStop = false;
                seek_bar.TickFrequency = 0;
                this.Controls.Add(seek_bar);
                duration.ForeColor = Color.White;
                duration.Font = new Font("Segoe UI", 8, FontStyle.Regular);
                this.Controls.Add(duration);
                timer1.Start();
                
            }
            private void autoResize()
            {//DMP003
                videoFrame.SetBounds(0,0,this.Width-16,this.Height-90);
                if (video != null) video.Size = videoFrame.Size;
                seek_bar.SetBounds(0,this.Height-90,this.Width-16,50);
                duration.SetBounds(this.Width-100,this.Height-75,100,15);
            }
            
            private void createNewVideo(String path) 
            {//DMP004
                try
                {
                    video = new Video(path);
                    video.Owner = videoFrame;
                    seek_bar.Maximum = (int)video.Duration;
                    video.Play(); 
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }
            private void videoFrame_dragDrop(object sender, DragEventArgs e) 
            {//DMP005
                string[] res = (string[])e.Data.GetData(DataFormats.FileDrop);
                String ext = res[0].Substring(res[0].LastIndexOf(".")+1);
                if (ext.ToLower().Equals("avi") || ext.ToLower().Equals("flv") || ext.ToLower().Equals("mp4") || ext.ToLower().Equals("wmv") || ext.ToLower().Equals("mkv"))
                {
                    createNewVideo(res[0]);
                }
            }
            private void videoFrame_dragEnter(object sender, DragEventArgs e) 
            {//DMP006
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    e.Effect = DragDropEffects.Copy;
                }
                else
                {
                    e.Effect = DragDropEffects.None;
                }
            }
    
            private void Form1_Resize(object sender, EventArgs e)
            {//DMP007
                //autoResize();
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {//DMP008
                autoResize();
                if (video != null) 
                {
                    seek_bar.Value = (int)video.CurrentPosition;
                    duration.Text = video.Duration.ToString();
                }
            }
            private void videoFrame_doubleClick(object sender, EventArgs e) 
            {
                MessageBox.Show("Test");
                if (video != null) video.Fullscreen = true;
            }
        }
    }

  2. #2
    Join Date
    Jan 2010
    Posts
    1,133

    Re: need help regarding event

    Try commenting out video.Play(). Does it work then? It could be that some funky interaction is the culprit here. Do the other events you hooked up on the videoFrame work? The Video class is not a control, so it doesn't really cover your panel.
    Last edited by TheGreatCthulhu; March 17th, 2012 at 03:58 PM.

  3. #3
    Join Date
    Jan 2010
    Posts
    1,133

    Re: need help regarding event

    BTW, if that is the problem, maybe you could use the render-to-texture facilities of the video class?

  4. #4
    Join Date
    Mar 2012
    Posts
    17

    Re: need help regarding event

    Quote Originally Posted by TheGreatCthulhu View Post
    BTW, if that is the problem, maybe you could use the render-to-texture facilities of the video class?
    how i do that?

    anyway about the video.play();
    if i dont call it the video wont play ..

  5. #5
    Join Date
    Jan 2010
    Posts
    1,133

    Re: need help regarding event

    Quote Originally Posted by Neolitz View Post
    anyway about the video.play();
    if i dont call it the video wont play ..
    I know that, smarty pants!
    I suggested that as an experiment to verify if the call to video.Play() is indeed the source of the problem. I was thinking that, for some reason, the way that the video is rendered to the control somehow interferes with the normal windows message loop, which results in certain events not being raised at all.
    My question was: if you comment out that line, do the events work as expected? This will help you rule out other potential causes of the problem.

    Quote Originally Posted by Neolitz View Post
    how i do that? [render-to-texture]
    Honestly, I currently don't know, and won't know for sure until I find time to experiment with the API myself. But from what I could gather from the documentation (here, and here), it should be something along these lines:

    • The idea is to render the video to an off-screen texture, and than display that texture on a quad rendered in the viewport.
    • So, you'll need to add a reference to Microsoft.DirectX.Direct3D, and create a Device instance. You might want to search for some tutorials to help you with that.
    • After you setup your device, you need to define a quad (two triangles), assign positions and UV texture coordinates to the vertices, so that the quad covers the entire client area of your videoFrame; the texture should fit exactly onto the quad. There should be some tutorials out there on that too.
    • Then you would call video.RenderToTexture(device) to enable the video object to trigger the TextureReadyToRender events whenever a frame is rendered.
    • Assign an event handler to the TextureReadyToRender event; the TextureRenderEventArgs contain a member property named Texture, that should contain your rendered frame. The event handler would then set that texture to the device, and render the quad.
    • This should enable the click event to function normally - but I'm not sure; you'll need to test it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured