#!/usr/bin/perl
#use strict;
#use warnings;
#use Switch;

#my $pid = fork(); exit 0 if $pid != 0;

my $retry_interval = 3;

my $bin = "/opt/interm/bin";
my $conf = "/opt/interm/conf";

my $xml_util = "$bin/xml_util";

my $oper_xml_file = "oper_mode.xml";
my $oper_mode_path = "/config/type";
my $oper_mode;
my $radio_enable; 

my $radio_xml_file = "radio.xml";
my $radio_enable_path = "/config/enable";
my $radio_url_path = "/config/url";

$oper_mode=`$xml_util -r -f $conf/$oper_xml_file -t $oper_mode_path`;
exit 1 if $? != 0;

while($oper_mode eq "radio") {
	$radio_enable=`$xml_util -r -f $conf/$radio_xml_file -t $radio_enable_path`;
	exit 1 if $? != 0;

	if ($radio_enable eq "yes") {
		qx!nice --5 mplayer $ARGV[0]!;	
	}
	sleep $retry_interval;

	$oper_mode=`$xml_util -r -f $conf/$oper_xml_file -t $oper_mode_path`;
	exit 1 if $? != 0;
}

