Commits

Toby Inkster committed e2fa85e

no, I do not like this temp file stuff for IPC, but it will do for now

Comments (0)

Files changed (3)

lib/SoundSwarm/Client/Player.pm

 	pause
 	skip
 	is_playing
+	current_song
 ));
 
 1;

lib/SoundSwarm/Daemon/Player.pm

 	is      => 'lazy',
 	isa     => InstanceOf[ 'SoundSwarm::MPlayer' ],
 	handles => {
-		play       => 'play',
-		skip       => 'stop',
-		pause      => 'pause',
-		wait       => 'wait',
-		is_playing => 'is_playing',
+		play         => 'play',
+		skip         => 'stop',
+		pause        => 'pause',
+		wait         => 'wait',
+		is_playing   => 'is_playing',
+		current_song => 'current_song',
 	},
 );
 
 {
 	my ($self, $method) = @_;
 	{
-		pause      => 1,
-		skip       => 1,
-		is_playing => 1,
+		pause        => 1,
+		skip         => 1,
+		is_playing   => 1,
+		current_song => 1,
 	}->{$method};
 }
 

lib/SoundSwarm/MPlayer.pm

 	},
 );
 
+has info => (
+	is      => 'ro',
+	isa     => Str,
+	default => sub {
+		my $info = "File::Spec"->catfile("File::Spec"->tmpdir, 'soundswarm-mplayer.info');
+		1 while unlink $info;
+		return $info;
+	},
+);
+
 sub play
 {
 	my $self = shift;
 	my ($filename) = @_;
 	
 	if (my $pid = fork) {
+		open my $fh, '>', $self->info;
+		print $fh $filename;
+		close $fh;
 		$self->_set_mplayer_pid($pid);
 		return $self;
 	}
 	
-	else {			
+	else {
+		no warnings;
 		exec(
 			$self->mplayer_path,
 			'-slave'        => (),
 			'-input'        => join("=", file => $self->fifo),
 			'-really-quiet' => (),
 			$filename,
-		) or confess "Unable to exec mplayer: $!";
+		);
+		confess "Unable to exec mplayer: $!";
 	}
 }
 
 	waitpid($self->mplayer_pid, 0);
 }
 
+sub current_song
+{
+	my $self = shift;
+	open my $fh, '<', $self->info;
+	scalar <$fh>;
+}
+
 1;