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:

sub must be a CODE reference at C:/Perl/site/lib/Wx/App.pm line 36.
probably due to my invented parameters. Thanks in Advance.

#!/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;

In reply to Can't get wxMedia sample code to work by Steve_BZ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.