POE::Component::Audio::Mad::Dispatch

POE::Component::Audio::Mad::Dispatch is a POE::Component::Audio::Mad frontend implementing listener based message dispatch.
Download

POE::Component::Audio::Mad::Dispatch Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Mark McConnell
  • Publisher web site:
  • http://search.cpan.org/~mischke/Audio-Mad-0.6/lib/Audio/Mad/Stream.pm

POE::Component::Audio::Mad::Dispatch Tags


POE::Component::Audio::Mad::Dispatch Description

POE::Component::Audio::Mad::Dispatch is a POE::Component::Audio::Mad frontend implementing listener based message dispatch. POE::Component::Audio::Mad::Dispatch is a POE::Component::Audio::Mad frontend implementing listener based message dispatch.SYNOPSIS use POE; use POE::Component::Audio::Mad::Dispatch; ## we print some stuff below, and we don't want it ## to get buffered.. so turn on autoflush. $| = 1; ## create our frontend session, which will create a decoder and ## forward it's messages to all interested listeners.. create POE::Component::Audio::Mad::Dispatch({ decoder_play_on_open => 1, alias => 'mad-decoder' }); POE::Session->create(inline_states => { _start => &ex_start, mad_decoder_input => &ex_input }); sub ex_start { my ($kernel, $heap, $session) = @_; ## add ourself in as a listener, and register for the DECODER_FRAME_DATA and ## IPC_SHUTDOWN_SUCCESS events. The decoder core will then call the ## 'mad_decoder_input' state in the current session when these ## events arrive.. ## this also has the added benefit of keeping a reference to our ## session alive in the event notification list. Our session will ## remain alive as long as we are a registered listener.. $heap->{lid} = $kernel->call('mad-decoder', 'add_listener', $session, 'mad_decoder_input', ); ## tell our decoder to start playing a stream.. $kernel->post('mad-decoder', 'decoder_open', { filename => '/path/to/stream.mp3', play => 1 }); } sub ex_input { my ($kernel, $heap, $msg) = @_; ## this is called when the decoder has generated an event ## that we have registered for. the message packet is ## contained in ARG0, and is a hashref with two ## fields ->{id} and ->{data}. id specifies the name ## of the event, and data contains a reference to ## the data included in this event.. if ($msg->{id} eq 'DECODER_FRAME_DATA') { ## we got a message updating us as to player ## progress, the data part of the event will ## contain two values: ->{played} and ->{progress}, ## played is the number of seconds of stream ## played.. print "rplayed: $msg->{data}->{played}" if (defined($msg->{data}->{played})); } elsif ($msg->{id} eq 'INPUT_EOF_WARNING') { ## we got a message telling us that the ## decoder system has come to the end of ## the current stream, use it as a queue ## to shutdown.. print "nshutting down..n"; $kernel->post('mad-decoder', 'decoder_shutdown'); } else { ## unknown messages should never happen, but ## we could do something interesting with them ## here.. for simplicity, we just ignore it. return; } } ## start this thing.. $poe_kernel->run(); exit();POE::Component::Audio::Mad::Dispatch implements a multiple dispatch front end component for the POE::Wheel::Audio::Mad mpeg decoder. It receieves status messages from the decoder and dispatches them to other registered "listener" sessions. All of the states listed in POE::Wheel::Audio::Mad(3) under STATES will be defined within this components session. To control the decoder, simply post the appropriate POE::Wheel::Audio::Mad STATE to this session.If you intend to implement a decoder that will be controlled and/or monitored by other POE::Session's, then this is the module you want to be using. If you wish to implement a decoder through an IPC bridge, you want POE::Component::Audio::Mad::Handle. Requirements: · Perl


POE::Component::Audio::Mad::Dispatch Related Software