Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Wx::MediaCtrl and Wx::PaintDC

by Steve_BZ (Chaplain)
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
# 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 );
                                # 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], );
+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_BUTTON( $self, $self->{Ctl_Videos_Button}, \&on_med
+ia_load );


    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 );
package main;

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

    my $frame_1 = MyFrame->new();


Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2023-12-04 23:16 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (25 votes). Check out past polls.