Beefy Boxes and Bandwidth Generously Provided by pair Networks Russ
Perl-Sensitive Sunglasses
 
PerlMonks  

Wx::MediaCtrl and Wx::PaintDC

by Steve_BZ (Hermit)
on Sep 14, 2009 at 14:20 UTC ( #795142=sourcecode: print w/ replies, xml ) Need Help??

Category: wxPerl
Author/Contact Info
Description: When I was starting to use wxPerl, I couldn't find enough examples of this control. So here is a small example here of wxMediaCtrl, and the beginning of a Bitmap Status bar underneath using DC::Paint.

#!/usr/bin/perl -w -- 

use Wx 0.15 qw[:allclasses];
use strict;

package MyFrame;

use Wx qw[:everything];
use base qw(Wx::Frame);
use strict;

sub new {
    my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_
+;
    $parent = undef              unless defined $parent;
    $id     = -1                 unless defined $id;
    $title  = ""                 unless defined $title;
    $pos    = wxDefaultPosition  unless defined $pos;
    $size   = wxDefaultSize      unless defined $size;
    $name   = ""                 unless defined $name;

    $style = wxDEFAULT_FRAME_STYLE 
        unless defined $style;

    $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $sty
+le, $name );
    $self->SetTitle("Draw/Video Controls");
    
    $self->{Ctl_Videos_Sizer_2} = Wx::BoxSizer->new(wxVERTICAL);      
+  # Top-level left-hand sizer (contains media)

# wxMEDIABACKEND_DIRECTSHOW     Use ActiveMovie/DirectShow. Requires w
+xUSE_DIRECTSHOW to be enabled, requires linkage with the static libra
+ry strmiids.lib, and is available on Windows Only.
# wxMEDIABACKEND_QUICKTIME     Use QuickTime. Windows and Mac Only. NO
+TE: On Mac Systems lower than OSX 10.2 this defaults to emulating win
+dow positioning and suffers from several bugs, including not working 
+correctly embedded in a wxNotebook.
# wxMEDIABACKEND_MCI         Use Media Command Interface. Windows Only
+.
# wxMEDIABACKEND_GSTREAMER    Use GStreamer. Unix Only. 
# wxMEDIABACKEND_WMP10        Windows Media Player 9 or 10
# wxMEDIABACKEND_REALPLAYER    Realplayer
# Blank             Allow to choose own player

    $self->{Ctl_Videos_Media}= Wx::MediaCtrl->new( $self, wxID_ANY, ''
+, wxDefaultPosition, [400,300],0,  );
    $self->{Ctl_Videos_Media}->Show( 1 );
    $self->{Ctl_Videos_Media}->ShowPlayerControls(wxMEDIACTRLPLAYERCON
+TROLS_DEFAULT);
                                # or wxMEDIACTRLPLAYERCONTROLS_NONE
                                # wxMEDIACTRLPLAYERCONTROLS_STEP
                                # wxMEDIACTRLPLAYERCONTROLS_VOLUME
                                # wxMEDIACTRLPLAYERCONTROLS_DEFAULT

    $self->{Ctl_Videos_Sizer_2}->Add( $self->{Ctl_Videos_Media}, 0, 0,
+ 0  );
    $self->{Ctl_Videos_ImageViewer_Panel_1} = Wx::Panel->new($self, wx
+ID_ANY, wxDefaultPosition, [400,20], );
    $self->{Ctl_Videos_Sizer_2}->Add($self->{Ctl_Videos_ImageViewer_Pa
+nel_1}, 0, 0, 0);
    $self->{Ctl_Videos_Button} = Wx::Button->new($self, wxID_ANY, "Loa
+d", );
    $self->{Ctl_Videos_Sizer_2}->Add($self->{Ctl_Videos_Button}, 0, 0,
+ 0);


    Wx::Event::EVT_PAINT($self->{Ctl_Videos_ImageViewer_Panel_1},\&pai
+nt);
    Wx::Event::EVT_BUTTON( $self, $self->{Ctl_Videos_Button}, \&on_med
+ia_load );

    $self->SetSizer($self->{Ctl_Videos_Sizer_2});
    $self->{Ctl_Videos_Sizer_2}->Fit($self);
    $self->Layout();

    return $self;
}
sub on_media_load {
#
#    Load file button selected
#
    my( $self, $event ) = @_;

    my $file = Wx::FileSelector('Choose a media file');    # Select vi
+deo file
    if( length( $file ) ) {
        $self->{Ctl_Videos_Media}->LoadFile ($file);        # Load vid
+eo file
    $self->{mediafile}= $file;            # Store location of video fi
+le in '$self
#    $self->{Ctl_Videos_Media}->Play();

    }
}
sub paint{
    my ($self,$event) = @_;
    my $dc = Wx::PaintDC->new($self);
    $dc->DrawRectangle( 0,0, 400,20 );
    $event->Skip;
}
package main;

unless(caller){
    local *Wx::App::OnInit = sub{1};
    my $app = Wx::App->new();
    Wx::InitAllImageHandlers();

    my $frame_1 = MyFrame->new();

    $app->SetTopWindow($frame_1);
    $frame_1->Show(1);
    $app->MainLoop();
}

Comment on Wx::MediaCtrl and Wx::PaintDC
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://795142]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2014-04-18 21:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (472 votes), past polls