NAME
Roku::RCP - Object approach to controlling RCP enabled Roku products, such as the Roku SoundBridge.
SYNOPSIS
use Roku::RCP;
# Connect to the sleeping Roku, wake him up and tell him to play
# the All_Dynamic playlist
my $rcp = new Roku::RCP('192.168.0.102');
# You can leave out this whole if-statement if your Roku is already
# connected to a media server (and thus not in standby mode).
if (!$rcp->GetConnectedServer()) {
print "Not connected to firefly. Connecting ...\n";
die "Couldn't connect to Firefly\n" unless $rcp->ServerConnectByName("Firefly");
}
$rcp->PlayPlaylist("All_Dynamic") or die "No Can Do\n";
$rcp->Shuffle("on");
$rcp->Quit();
DESCRIPTION
Roku::RCP
Gives you an object through which you can communicate with your Roku Control Protocol-enabled Roku product. For the most part, the commands are merely passed through onto the connection and the results are parsed and returned to you either in an array in list context, or a giant string in scalar context. Should the command fail, undef is returned.
You'll want to familiarize yourself with the Roku Control Protocol (RCP) by visting the Roku Labs site http://www.rokulabs.com and reading the RCP spec. Although this module provides some convenience functions, you'll need to have an understanding of the basic commands if you'd like to do anything more fancy. If you're not into reading, you can telnet to port 5555 on your Roku yourself and type "help".
METHODS
my $rcp = new Roku::RCP($hostname, %options)
-
Construct a new object.
$rcp = new Roku::RCP('192.168.0.102', Debug=>0, RawResults=>0, Port=>5555, Timeout=>50);
If RawResults is set, you'll get back everything Roku sends back. If it's not set, you'll just get back the data without any metadata. Be careful with RawResults because the data and metadata will be intermixed so if you have code expecting just the results, you'll be in for an unpleasant surprise. Everything after the hostname is optional. The proper defaults will be chosen.
See the System Commands section for how to use Roku::RCP to send system-type commands instead of media playback-type commands.
$rcp->ServerConnectByName($server_name)
-
ServerConnectByName()
Is a convenience function that takes a partial or complete media server name and tries to connect to it. An example of such would be "FireFly"; $rcp->PlayPlayList($playlist_name)
-
A convenience function that takes a partial or complete playlist name and tries to start playing it.
$rcp->PlayArtist($artist_name)
-
A convenience function that takes an exact, case-sensitive artist name and tries to play all the songs by that artist. Note that if you'd like to do partial matching, you'll have to first call $rcp->SearchArtists("vast"), get the resulting list back, pick one and then call PlayArtist() with that string.
$rcp->PlayAlbum($album_name)
-
A convenience function that takes an exact, case-sensitive album name and tries to play all the songs on that album. Note that if you'd like to do partial matching, you'll have to first call $rcp->SearchAlbums("visual audio sensory theat"), get the resulting list back, pick one and then call PlayAlbum() with that string.
$rcp->PlaySong($song_name)
-
A convenience function that takes a partial, case insensitive song name and tries to play all the songs matching that string.
$rcp->InsertSong($song_name)
-
A convenience function that takes a partial, case insensitive song name and tries to insert all matching songs into the queue and play them. Note that if the song/s is/are already in your queue, the position won't change and the next song in your queue will start playing.
$rcp->Quit()
-
Cleanly close the connection. This will get called automatically when the object is destroyed.
$rcp->ROKU_RCP_COMMAND($arg1, $arg2, ...)
-
Any commands not specifically listed here are considered to be RCP commands and sent along down the connection. Here are a few to wet your whistle: Next, Previous, Reboot, QueueAndPlay, GetTimeZone, ListServers, ListPlaylists. Generally the paradigm is that you connect to Roku, issue a command that lists out songs and then you QueueAndPlay. Roku assumes you mean the last listing of songs. Unless you want to wait for thousands and thousands of song titles to come back, you generally want to tell Roku to forgo sending you the entire list and just send you the total number. $rcp->SetListResultType("partial") is your friend. Take a look at how I did the PlayArtist() convenience function as a good starting place.
System Commands
Port 5555 deals with media playback and control thereof. If you'd like to use Roku::RCP to send system-type commands to the 4444 control port, you should use the command() call. For example, if you wanted to create a script that notifies you of some event:
my $msg = 'Hey, look over here';
my @slides = (5, -5, 10, -5, -5);
$rcp = new Roku::RCP('192.168.0.102', Port=>4444);
$rcp->command('attract') foreach (1..5);
$rcp->command('sketch');
$rcp->command('font 14');
$rcp->command('clear');
$rcp->command("text 0 0 \"$msg\"");
foreach $slide (@slides) {
sleep 2;
$rcp->command("slide $slide 20");
}
sleep(4);
$rcp->Quit();
LEGALESE
Copyright 2007 by Robert Powers, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
2007, Robert Powers <batman@cpan.org>