#!/usr/bin/perl
#use strict;
#use warnings;
use Switch;
use Getopt::Long;

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 $radio_xml_file = "radio.xml";
my $radio_enable_path = "/config/enable";
my $radio_url_path = "/config/url";
my $radio_name_path = "/config/name";

my $args;

my $mode = '';
my $path = '';
my $play = '';
my $stop = '';

my $result = GetOptions(	"mode=s" => \$mode,
							"path=s" => \$path,
							"play" => \$play,
							"stop" => \$stop,
						);

exit 0 if ($mode eq '');

switch($mode) {
	case "usb" {
		$args = "-m usb";

		my $disk_exist = qx!mount | grep /mnt/removable_disk!;
		if ($disk_exist =~ m!/mnt/removable_disk! && -e '/mnt/removable_disk/playlist.m3u') {
			$args .= " -p /mnt/removable_disk/playlist.m3u";
		}
	}
	case "radio" {
		$args = "-m iradio";
		$args .= " -p \"$path\"" if (length($path) > 0);
		$args .= " --play" if ($play == 1);
		$args .= " --stop" if ($stop == 1);
	}
	case "aoe" {
		$args = " -m aoe";
		$args .= " --play" if ($play == 1);
		$args .= " --stop" if ($stop == 1);
	}
}

qx!/opt/interm/bin/aplayer_ctrl $args!; 
print qq!/opt/interm/bin/aplayer_ctrl $args\n!; 

