Steve_BZ has asked for the wisdom of the Perl Monks concerning the following question:
Hi Worshipful monks, I'm trying to use wxMedia http://docs.wxwidgets.org/stable/wx_wxmediactrl.html, but I can't get the demo code to work. Does anyone have any working code showing how to use wxMedia?
I've posted the code I'm trying to use below. There are probably many errors, but the one I know about is on the last but one line.
my $app = MyApp->new(1,1);
I guess the values should be those from $class, $parent, but I'm a bit lost here!
What I hope to get is a media player displayed in a window, prompting me for a media file. What I actually get is no window and an error:
probably due to my invented parameters. Thanks in Advance.sub must be a CODE reference at C:/Perl/site/lib/Wx/App.pm line 36.
#!/usr/bin/perl -w ###################################################################### +####### ## Name: lib/Wx/DemoModules/wxMediaCtrl.pm ## Purpose: wxPerl demo helper for Wx::MediaCtrl ## Author: Mattia Barbon ## Modified by: ## Created: 03/04/2006 ## RCS-ID: $Id: wxMediaCtrl.pm 2189 2007-08-21 18:15:31Z mbarbon +$ ## Copyright: (c) 2006 Mattia Barbon ## Licence: This program is free software; you can redistribute it + and/or ## modify it under the same terms as Perl itself ###################################################################### +####### use strict; use Wx; # package Wx::DemoModules::wxMediaCtrl; package MyMediaCtrl; use strict; use base qw(Wx::Panel Class::Accessor::Fast); use base qw(Wx::DemoModules::wxMediaCtrl); use Wx qw(:sizer); use Wx::Media; use Wx::Event qw(EVT_MEDIA_LOADED EVT_BUTTON); __PACKAGE__->mk_ro_accessors( qw(media) ); sub new { my( $class, $parent ) = @_; my $self = $class->SUPER::new( $parent, -1 ); my $media = Wx::MediaCtrl->new( $self, -1, '', [-1,-1], [-1,-1], 0 + ); $self->{media} = $media; my $media_load = Wx::Button->new( $self, -1, 'Load a media file' ) +; my $sz = Wx::BoxSizer->new( wxVERTICAL ); $sz->Add( $media, 1, wxGROW ); $sz->Add( $media_load, 0, wxALL, 5 ); $media->Show( 1 ); $media->ShowPlayerControls; $self->SetSizer( $sz ); EVT_MEDIA_LOADED( $self, $media, \&on_media_loaded ); EVT_BUTTON( $self, $media_load, \&on_media_load ); return $self; } sub on_media_loaded { my( $self, $event ) = @_; Wx::LogMessage( 'Media loaded, start playback' ); $self->media->Play; } sub on_media_load { my( $self, $event ) = @_; my $file = Wx::FileSelector( 'Choose a media file' ); if( length( $file ) ) { $self->media->LoadFile( $file ); } } sub add_to_tags { qw(controls) } sub title { 'wxMediaCtrl' } # defined &Wx::MediaCtrl::new ? 1 : 0; package MyApp; use base 'Wx::App'; sub OnInit { my $frame = MyMediaCtrl->new; $frame->Show( 1 ); } package main; my $app = MyApp->new(1,1); $app->MainLoop;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: wxMedia sample code
by ww (Archbishop) on Feb 04, 2009 at 20:46 UTC |