Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 03-21-2006, 12:29 AM   #1
Beta Member
 
Join Date: Mar 2006
Posts: 1
Question PHP commands.

I am having a problem. There is a PHP file that can be run through any web server on my computer, and it will still control the iTunes music player, So I was wondering how to get it to control other things. It has to be in the PHP, because any web server can run it. Here is the file:

Code:
<HTML>
	<HEAD>
		<META http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
		<TITLE>iTunesRemote</TITLE>
	</HEAD>
<?php
	// author: k7m (k7m@gmx.at)
	$iTunesApp = new COM('iTunes.Application') or die("Unable to instanciate iTunesApp"); 
	$pathToHTTPDir = "C:\\Programme\\XAMPP\\htdocs\\PSP\\";
	
	$action = "";
	$searchtext ="";
	
	if (isset($_GET['action']))
		$action = $_GET['action'];
		
	if (isset($_REQUEST['searchtext']))
		$searchtext = $_REQUEST['searchtext'];
		
	if ($action == "previous")
	{
		$iTunesApp->PreviousTrack ();
	}
	else if ($action == "next")
	{
		$iTunesApp->NextTrack ();
	}
	else if ($action == "playtrack")
	{
		$sourceID					= 0;
		$playlistID				= 0;
		$trackID					= 0;
		$trackdatabaseID	= 0;


		if (isset($_GET['sourceID']))
			$sourceID = $_GET['sourceID'];
		if (isset($_GET['playlistID']))
			$playlistID = $_GET['playlistID'];
		if (isset($_GET['trackID']))
			$trackID = $_GET['trackID'];
		if (isset($_GET['trackdatabaseID']))
			$trackdatabaseID = $_GET['trackdatabaseID'];
	
		settype($sourceID, "integer");
		settype($playlistID, "integer");
		settype($trackID, "integer");
		settype($trackdatabaseID, "integer");
		
		$track = $iTunesApp->GetITObjectByID ($sourceID, $playlistID, $trackID, $trackdatabaseID);
		$track->Play ();
	}
	else if ($action == "play")
	{
		$iTunesApp->Play ();
	}
	else if ($action == "pause")
	{
		$iTunesApp->Pause ();
	}
	else if ($action == "volume_up")
	{
		$volume = $iTunesApp->SoundVolume ();
		$iTunesApp->SoundVolume = $volume + 10;
	}
	else if ($action == "volume_down")
	{
		$volume = $iTunesApp->SoundVolume ();
		$iTunesApp->SoundVolume = $volume - 10;
	}
	
	$playerState = 	$iTunesApp->PlayerState;
	$volume = $iTunesApp->SoundVolume;
	
?>

	<BODY leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" >
		<TABLE width="480" background="player_bkgnd.png" cellpadding="0" cellspacing="0">
			<TR>
				<TD height="40" align="left">
					<IMG SRC="space.png" height="40" width="2" border="0"><A HREF="iTunesRemote.php?action=previous&rand=<?php echo rand (); ?>"><IMG SRC="btn_player_previous.png" border="0"></A><IMG SRC="space.png" height="40" width="6" border="0"><?php if ($playerState == 0) { ?><A HREF="iTunesRemote.php?action=play&rand=<?php echo rand (); ?>"><IMG SRC="btn_player_play.png" border="0"></A><?php } else { ?><A HREF="iTunesRemote.php?action=pause&rand=<?php echo rand (); ?>"><IMG SRC="btn_player_pause.png" border="0"></A><?php } ?><IMG SRC="space.png" height="40" width="6" border="0"><A HREF="iTunesRemote.php?action=next&rand=<?php echo rand (); ?>"><IMG SRC="btn_player_next.png" border="0"></A><IMG SRC="space.png" height="40" width="20" border="0"><A HREF="iTunesRemote.php?action=volume_down&rand=<?php echo rand (); ?>"><IMG SRC="btn_player_quieter.png" border="0"></A><IMG SRC="space.png" height="40" width="6" border="0"><IMG SRC="volume_bar_begin.png" title="<?php echo $volume?>"><IMG SRC="volume_bar_line.png" title="<?php echo $volume?>" height ="40" width="<?php echo $volume?>"><IMG SRC="volume_bar_dot.png" title="<?php echo $volume?>"><IMG SRC="volume_bar_line.png" title="<?php echo $volume?>" height="40" width="<?php echo (100-$volume)?>"><IMG SRC="volume_bar_end.png" title="<?php echo $volume?>"><IMG SRC="space.png" height="40" width="6" border="0"><A HREF="iTunesRemote.php?action=volume_up&rand=<?php echo rand (); ?>"><IMG SRC="btn_player_louder.png" border="0"></A>
				</TD>
				<TD height="40" align="right">
					<FORM method="POST" id="iTunesSearch" action="iTunesRemote.php">
						<INPUT name="searchtext" type="text" id="searchtext" size="20"><IMG SRC="space.png" height="10" width="4" border="0"><INPUT type="image" src="btn_player_search.png">
					</FORM>
				</TD>
			</TR>
		</TABLE>
<?php

	$track = $iTunesApp->CurrentTrack ();
	$album = $track->Album ();
	$artist = $track->Artist ();
	$name = $track->Name ();

	if (strlen ($album) > 0)
		$fullName = sprintf ("%s - %s - %s", $artist, $album, $name);
	else
		$fullName = sprintf ("%s - %s", $artist, $name);

	$hasArtwork = false;
	if (strlen ($fullName) > 3)
	{
		$artworkColl = $track->Artwork;
		$cntArtwork = $artworkColl->Count;

		if ($cntArtwork > 0)
		{
			$artwork = $artworkColl->Item (1);
			$artworkPath = sprintf ("%s\\%s", $pathToHTTPDir, "artwork.jpg");
			$artwork->SaveArtworkToFile ($artworkPath);
			$hasArtwork = true;
		}
	}
	else
		$fullName = "nothing";

?>
		<TABLE cellpadding="0" cellspacing="0" width="480">
			<TR>
				<TD>
					<B><CENTER><?php echo $fullName; ?></CENTER></B>
				</TD>
			</TR>
	
<?php
	if ($hasArtwork && strlen ($searchtext) == 0)
	{
?>
			<TR>
				<TD height="210" align="bottom">
					<CENTER><IMG src="artwork.jpg" border="0" height="200" widht="200"></CENTER>
				</TD>
			</TR>
<?php
	}
?>
		</TABLE>
<?php

	if (strlen ($searchtext) > 0)
	{
		$mainLibrary = $iTunesApp->LibraryPlaylist ();
		$tracks = $mainLibrary->Search ($searchtext, 0);
		$cntTracks = $tracks->Count ();
	
		if ($cntTracks > 0)
		{
?>
<BR>
found <B><?php echo $cntTracks; ?><B> result(s) for <B><?php echo $searchtext; ?></B>:
		<TABLE cellpadding="0" cellspacing="0" width="480">
<?php		
			for ($i = 1; $i <= $cntTracks; $i++)
			{
				$curTrack = $tracks->Item($i);
				$album = $curTrack->Album ();
				$artist = $curTrack->Artist ();
				$name = $curTrack->Name ();
		
				if (strlen ($album) > 0)
					$fullName = sprintf ("%s - %s - %s", $artist, $album, $name);
				else
					$fullName = sprintf ("%s - %s", $artist, $name);
	
		
				$sourceID = $curTrack->SourceID;
				$playlistID = $curTrack->PlaylistID;
				$trackID = $curTrack->TrackID;
				$trackdatabaseID = $curTrack->TrackdatabaseID;
				
				if ($i % 2 == 0)
					$bgcolor="#FFFACD";
				else
					$bgcolor="#F0F8FF"
			
?>
			<TR bgcolor="<?php echo $bgcolor; ?>">
				<TD>
					<A HREF="iTunesRemote.php?action=playtrack&sourceID=<?php echo $sourceID; ?>&playlistID=<?php echo $playlistID; ?>&trackID=<?php echo $trackID; ?>&trackdatabaseID=<?php echo $trackdatabaseID; ?>&rand=<?php echo rand (); ?>"><IMG SRC="btn_player_play_small.png" border="0"></A>
				</TD>
				<TD width="6">
				</TD>
				<TD>
						<?php echo $fullName; ?>
				</TD>
			</TR>
<?php		
			}
?>
		</TABLE>
<?php
		}
	}
?>

	</BODY>
</HTML>


<?php
	$iTunesApp->Release();
	$iTunesApp = null;
	unset($iTunesApp);
?>
bill795 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 06:40 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0