#!perl
use v5.12;
use warnings;
use GStreamer1;
use Glib qw( TRUE FALSE );
my $URI = shift || die "Need URI to play\n";
my $loop = Glib::MainLoop->new( undef, FALSE );
GStreamer1::init([ $0, @ARGV ]);
my $pipeline = GStreamer1::parse_launch( "playbin uri=$URI" );
my $bus = $pipeline->get_bus;
$bus->add_watch( \&bus_callback, $loop );
$pipeline->set_state( "playing" );
$loop->run;
$pipeline->set_state( "null" );
sub bus_callback
{
my ($bus, $message, $loop) = @_;
if( $message->type & "error" ) {
warn $message->error;
$loop->quit;
}
elsif( $message->type & "eos" ) {
$loop->quit;
}
return TRUE;
}