[HOW-TO] Control iTunes via Web Browser (MAC ONLY)

slooksterpsv

MacTechie17
HOW-TO:
NOTE: YOU CAN USE ANY BROWSER ON ANY OS TO CONTROL iTunes BUT YOU CAN ONLY SET IT UP ON MAC - THIS WILL NOT WORK ON WINDOWS CAUSE YOU DON'T HAVE THE UNIX COMMANDS TO CONTROL IT.
WARNING: THIS MAKES SECURITY RISKS ON YOUR COMPUTER!
Step 1 - Modify httpd.conf
1) Open Terminal and locate to the patch /etc/httpd type in sudo pico httpd.conf
A lot of these things you'll have to find within httpd.conf - but after you do one, it'll be next down the line:

Take the # off of LoadModule php4_module libexec/httpd/libphp4.so
Take the # off of AddModule mod_php4.c
Find:
#
User www
Group www

and change it to
#
User your_short_username #mine is sbarn
Group staff

Find:
<IfModule mod_dir.c>
DirectoryIndex index.html
</IfModule>

Add a space after index.html and add index.php
Hit Control O to bring up the save file at the bottom, hit enter then control X to exit.

Next type:
sudo apachectl graceful

Now for Step 2 - Creating the PHP File
2)I'm changing this site so you guys can make it just that awesome, here's the code that you place in the index.php - I cut the image from iTunes via Command + Shift + 4 - here's the entire code:
PHP:
<html>
<head>
<!-- < $url = "index.html";
<echo "<META HTTP-EQUIV=refresh content=0;URL=$url>" > //-->
<title>Remote Control iTunes</title>
</head>
<body>
<?
$q = $_GET['q'];
switch ($q)
{
case "";
//echo "You need to send me a command, then I shall execute it";
break;
case "play";
exec("osascript -e 'tell app \"iTunes\" to play'");
//echo "Playing";
break;

case "pause";
exec("osascript -e 'tell app \"iTunes\" to pause'");
//echo "Pausing";
break;

case "playpause";
exec("osascript -e 'tell app \"iTunes\" to playpause'");
//echo "Toggling Play";
break;

case "next";
exec("osascript -e 'tell app \"iTunes\" to next track'");
//echo "Next Track";
break;

case "prev";
exec("osascript -e 'tell app \"iTunes\" to previous track'");
//echo "Previous Track";
break;

case "louder";
exec("osascript -e 'tell app \"iTunes\" to set sound volume to sound volume + 5'");
//echo "Turning Up the Volume";
break;

case "quieter";
exec("osascript -e 'tell app \"iTunes\" to set sound volume to sound volume - 5'");
//echo "Turning Down the Volume";
break;
case "open";
exec("osascript -e 'tell app \"iTunes\" to open'");
break;
case "mute";
mutev();
//echo "Muting the Volume";
break;
}


function mutev()
{
//echo "start mute function<br>";

$data = file_get_contents("/Library/WebServer/Documents/volume.txt");

$logfile = fopen("/Library/WebServer/Documents/volume.txt",'w');

$oldvolume = exec("osascript -e 'tell app \"iTunes\" to sound volume'");

//echo "volume data:$data:<br>";
if ($data == "x")
{
fwrite($logfile,$oldvolume);
exec("osascript -e 'tell app \"iTunes\" to set sound volume to 0'");
}
else
{
fwrite($logfile,"x");
exec("osascript -e 'tell app \"iTunes\" to set sound volume to $data'");
}
fclose($logfile);
}

?>
<p>  <img src="Actions1.png" width="131" height="66" border="0" usemap="#Map">
  <map name="Map">
    <area shape="rect" coords="101,46,123,59" href="index.php?q=louder">
    <area shape="rect" coords="44,6,85,46" href="index.php?q=playpause">
    <area shape="rect" coords="11,9,43,45" href="index.php?q=prev">
    <area shape="rect" coords="87,8,117,44" href="index.php?q=next">
    <area shape="rect" coords="3,47,25,60" href="index.php?q=quieter">
  </map>
</p>
</body>
</html>
--notice what I commented out - read what the lines say, if you're webs server isn't where I have it (via /Library/WebServer/Documents) you need to change a few things then 2 lines that say that thing, change it to the location of your server, these lines:
$data = file_get_contents("/Library/WebServer/Documents/volume.txt");

$logfile = fopen("/Library/WebServer/Documents/volume.txt",'w');

Now in your terminal, type this (you may need to change /Library... to the location of your web server:
cd /Library/WebServer/Documents
pico volume.txt
Control+O
Enter
Control+X

Now type in: sudo chmod 777 volume.txt

Step 3 Test to see if it works:
3) Type into Safari, or whatever browser you want to use: ip_address/index.php
YAY IT SHOULD WORK =D, here's a copy of the files I used down at the bottom or top, its in a zip file.

The volume icons control the volume - the next and previous control the track - the play button controls play and pause.


OH MY GOSH - I FORGOT TO GIVE CREDIT WHERE CREDIT IS DUE: I found out how to do this here: http://www.whatsmyip.org/itunesremote/
 

Attachments

Top