Jump to content

on click, update variable?


flemingmike

Recommended Posts

hello all, is it possible to update an xml variable when a link is clicked.  my speciffic reason is i have an xml send that increases my volume.  i need the volume variable to update though when it is increased or decreased.  here is my code below:

 

<?php

include("style.php");

$hmm1 = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getvolume');

  
    $pc = 'player-command';    
    $vol = $hmm1->$pc->value;
    $volup = $hmm1->$pc->value +20;
    $voldown = $hmm1->$pc->value -20;



$hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.GetNowPlayingData');

foreach ($hmm->tracks as $tracks) {
    $ry = 'release-year';
    $artist = $tracks->track->artist;
    $title = $tracks->track->title;
    $album = $tracks->track->album;    
    $year = $tracks->track->$ry; 
    $genre = $tracks->track->genre;  
}



function decodeTime($seconds) {    
$mins = floor($seconds / 60);    
$secs = floor($seconds - ($mins * 60));    
if(strlen($secs) == 1) $secs = "0".$secs;    
return $mins.":".$secs;

}

$length = decodeTime($tracks->track->length);

//  Volume Percentage
function decodeTime1($seconds1) { 
$mins1 = floor($seconds);     
$secs1 = floor($seconds1 - ($mins1 / 2.55)); 
if(strlen($secs) == 1) $secs = "0".$secs;    
return "".$secs1;

}

$volper = decodeTime1($hmm1->$pc->value /2.55);







echo '<div id="musicinfo" align="center">		




<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
	<td align="center">



<table border="0" width="455">
<tr>
	<td rowspan="5" width="100">
<img border="0" src="http://www.durhamit.ca:8181/1.0/?method=player.getNowPlayingPicture" width="100" height="100"></td>
	<td align="center" width="87"><b>Artist:</b></td>
	<td>'.$artist.'</td>
	<td rowspan="5" align="center" width="64">
	<table border="0" width="47%" cellspacing="0" cellpadding="0">
		<tr>
			<td align="center"><a href="parse.php">
			<img border="0" src="images/Button-Refresh-icon.bmp" width="64" height="64"></a></td>
		</tr>
		<tr>
			<td align="center">Update</td>
		</tr>
	</table>
	</td>
</tr>
<tr>
	<td align="center" width="87"><b>Title:</b></td>
	<td>'.$title.'</td>
</tr>
<tr>
	<td align="center" width="87"><b>Album:</b></td>
	<td>'.$album.'</td>
</tr>
<tr>
	<td align="center" width="87"><b>Year:</b></td>
	<td>'.$year.'</td>
</tr>
<tr>
	<td align="center" width="87"><b>Length:</b></td>
	<td>'.$length.'</td>
</tr>

</table>




	</td>
</tr>
<tr>
	<td align="center">
	<table border="0" width="455">
		<tr>
			<td align="center">
			<a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.play">
			<img border="0" src="images/Button-Play-icon.bmp" width="64" height="64"></a></td>
			<td align="center">
			<a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.pause">
			<img border="0" src="images/Button-Pause-icon.bmp" width="64" height="64"></a></td>
			<td align="center">
			<a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.previous">
			<img border="0" src="images/Button-Previous-icon.bmp" width="64" height="64"></a></td>
			<td align="center">
			<a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.next">
			<img border="0" src="images/Button-Next-icon.bmp" width="64" height="64"></a></td>
		</tr>
		<tr>
			<td align="center">Play</td>
			<td align="center">Pause</td>
			<td align="center">Previous</td>
			<td align="center">Next</td>
		</tr>
		<tr>
			<td align="center" colspan="4">
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td align="center">
					<a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.setvolume&volume='.$voldown.'" 

href="http://www.google.ca">
					<img border="0" src="images/Button-Delete-icon.bmp" width="64" height="64"></a></td>
					<td align="center" width="20%"><font size="5">Volume<br>'.$volper.'%</font></td>
					<td align="center">
					<a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.setvolume&volume='.$volup.'">
					<img border="0" src="images/Button-Add-icon.bmp" width="64" height="64"></a></td>
				</tr>
			</table>
			</td>
		</tr>
		<tr>
			<td align="center"> </td>
			<td align="center"> </td>
			<td align="center">



			<iframe name="control" width="1" height="1" scrolling="no" frameBorder="0"></iframe>




			</td>
			<td align="center"> </td>
		</tr>
	</table>
	</td>
</tr>
<tr>
	<td align="center"> </td>
</tr>
<tr>
	<td align="center"> </td>
</tr>
</table>




   
</div>';




?>

Link to comment
Share on other sites

ok, so i have

 

$pc = 'player-command';        
$vol = $hmm1->$pc->value;
$volup = $hmm1->$pc->value +20;    
$voldown = $hmm1->$pc->value -20;

 

but when i click on

 

<a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.setvolume&volume='.$volup.'">						<img border="0" src="images/Button-Add-icon.bmp" width="64" height="64"></a>code]

it makes my volume go up +20, but it isnt updating the values, so if i click it again, the volume doesnt continue to go up.

Link to comment
Share on other sites

That's because $hmm->$pc->$value has a certain value that does not change.  All you're code is doing is adding or subtracting 20 to/from $hmm->$pc->$value.  You must make your volume dynamic so it can be altered and retain that altered value.

 

<?php
$pc 		= 'player-command';        
$vol 		= $hmm1->$pc->value;
$volup 		= ((isset($_GET['volume']) && ctype_digit($_GET['volume'])) ? htmlspecialchars($_GET['volume'], ENT_QUOTES) : $vol) + 20;    
$voldown 	= ((isset($_GET['volume']) && ctype_digit($_GET['volume'])) ? htmlspecialchars($_GET['volume'], ENT_QUOTES) : $vol) - 20;    

echo '<a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.setvolume&volume='. $volup .'">UP</a> | <a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.setvolume&volume='. $voldown .'">DOWN</a>';

 

Untested, but that's at least the logic.

Link to comment
Share on other sites

NOTE: you should implement some $min and $max controls as my code will allow for unlimited increments of 20, and will allow for volume to be decreased to -20 which I'm sure is not an expected result.

 

Perhaps you can give that a stab or somebody will be nice enough to rough it in for you.  Preferably, you should give it a shot.

Link to comment
Share on other sites

The code I gave you will increment to the $volup and $voldown variables as the code stands, however, you need to then use those variables in your code somewhere to actually influence the volume control which I don't see anywhere in your code.

Link to comment
Share on other sites

its in my code inside a table.

 

<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td align="center">
					<a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.setvolume&volume='.$voldown.'">
					<img border="0" src="images/Button-Delete-icon.bmp" width="64" height="64"></a></td>
					<td align="center" width="20%"><font size="5">Volume<br>'.$volper.'%</font></td>
					<td align="center">
					<a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.setvolume&volume='. $volup .'">
					<img border="0" src="images/Button-Add-icon.bmp" width="64" height="64"></a></td>
				</tr>
			</table>

 

 

 

my top code now looks like this:

 

$hmm1 = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getvolume');

$pc = 'player-command';        
$vol = $hmm1->$pc->value;
$volup = ((isset($_GET['volume']) && ctype_digit($_GET['volume'])) ? htmlspecialchars($_GET['volume'], ENT_QUOTES) : $vol) + 20;
$voldown = ((isset($_GET['volume']) && ctype_digit($_GET['volume'])) ? htmlspecialchars($_GET['volume'], ENT_QUOTES) : $vol) - 20;

Link to comment
Share on other sites

What I meant was, there must be a call to whatever it is that is creating the volume (Ex. radio, etc.), where a variable would have to be passed to have the sound play at a certain volume, ie:

 

$hmm1 = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getvolume&volume=whatever');

 

All you seem to have are the controls, but those controls must send their input to something which then renders the values and outputs them.  Or I'm really over-complicating things, either way, it's your code and not mine, so you should know it inside and out.

Link to comment
Share on other sites

here are my options, so im not sure if i can do what you suggest

 

 

"Method"                "Parameter"  "Response"    "Description"

player.getVolume    None              Default 

player.setVolume    volume            Default            Volume is set with a value between 0 (silent) and 255 (max).

 

Link to comment
Share on other sites

Don't give up, man.  You just need to understand that logic that you're missing.

 

Take this chunk and throw it in a file called test:

 

$vol 		= 0;
$volup 		= ((isset($_GET['volume']) && ctype_digit($_GET['volume'])) ? htmlspecialchars($_GET['volume'], ENT_QUOTES) : $vol) + 20;    
$voldown 	= ((isset($_GET['volume']) && ctype_digit($_GET['volume'])) ? htmlspecialchars($_GET['volume'], ENT_QUOTES) : $vol) - 20;    

echo '<a target="control" href="test.php?volume='. $volup .'">UP</a> | <a target="control" href="test.php?volume='. $voldown .'">DOWN</a>';

 

You'll be able to see what's going on and how it's working.

Link to comment
Share on other sites

ok, so i see how that is working now.  i just dont get how to take that and make it a variable?  if that is making any sense.?!?

Nope, doesn't make any sense.  Make what a variable?

 

It seems to me you've jumped into the deep end with weights around your ankles with code like this.  You will never get better at any language starting on projects that are far past your experience level.  You're just going to pick up bad practices and you will never have strong fundamentals in PHP.

 

I mean, if a project like this is a one-off thing and you're never going to touch PHP again, then sure, muscle through it.  But, if you're planning on using PHP again, or as a career choice, then I suggest you stop with the more experienced applications and pick up a guide for beginners and get the basics right.  It's the same with absolutely anything you do in life.  People just seem to have this notion that programming/scripting/etc is not difficult, and subsequently you see that come to life when people ask you to create an e-commerce website for them for $150, because that's their "budget".

 

It's a lot more difficult than you might think, however, you're probably picking up on that now.  And it won't get any easier.

 

/my 2 cents;

Link to comment
Share on other sites

for the xml send i have to make a url like http://ww......./method=player.setvolume&volume=(*a number between 1 and 255*)

 

but in order to get the current volume, i need to parse the xml from http://ww....../method=player.getvolume  and it is in the value portion. 

 

so i have it so that $vol = the value of value in the player.getvolume xml output.

 

so when i click $volup, which is a calculation of $vol +/- 20, i then need the $vol value to update accordingly.

Link to comment
Share on other sites

the server doesnt accept it as a getvolume&volume= , it hjas to passed at setvolume&volume=.

 

and ya, this is a one off project, and just for my own personal use.  i do alot of php stuff, but very very basic and just for my own stuff.

My bad, I wasn't paying much attention to the parameter names.  I've exhausted my time here for now, so just keep tinkering.

 

And let's pray that they don't sign him seeing as how he made such a difference for Jersey (not).  He's got a hell of a shot, but he's useless as an overall player.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.