flemingmike Posted June 12, 2010 Share Posted June 12, 2010 any idea why this is nt working? $hmm1 = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getvolume'); foreach ($hmm1->player-command as $volume1) { $vol = $volume1->value; } Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/ Share on other sites More sharing options...
kenrbnsn Posted June 12, 2010 Share Posted June 12, 2010 What's it supposed to do & what is it doing? Ken Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071187 Share on other sites More sharing options...
flemingmike Posted June 12, 2010 Author Share Posted June 12, 2010 its suposed to parse the xml file for the volume value. its not returning anything as the value though. Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071188 Share on other sites More sharing options...
ignace Posted June 12, 2010 Share Posted June 12, 2010 $hmm1->player-command should be: $hmm1->player->command Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071196 Share on other sites More sharing options...
kenrbnsn Posted June 12, 2010 Share Posted June 12, 2010 No, player-command is correct. Put the URL into a browser to see th XML being returned (Firefox, not Chrome). When I try the commands via PHP, the program hangs, so I have a feeling that the server is looking for some particular header. Ken Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071202 Share on other sites More sharing options...
flemingmike Posted June 12, 2010 Author Share Posted June 12, 2010 its not hanging for me. im bassically trying to make a volume up button: $volup = $volume1->value +50; $voldown = $volume1->value -50;[/ then link <a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.setvolume&volume='.$volup.'">Volume Up</a> thats my goal Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071209 Share on other sites More sharing options...
ignace Posted June 12, 2010 Share Posted June 12, 2010 No, player-command is correct. Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071212 Share on other sites More sharing options...
kenrbnsn Posted June 12, 2010 Share Posted June 12, 2010 Here's what's returned in the browser: <?xml version="1.0" encoding="UTF-8"?> <hmm status="ok"> <player-command> <command>volume</command> <value>179</value> <value2>0</value2> <value3></value3> </player-command> </hmm> Ken Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071214 Share on other sites More sharing options...
flemingmike Posted June 12, 2010 Author Share Posted June 12, 2010 yes. i need $vol to = this field <value>179</value> Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071215 Share on other sites More sharing options...
ignace Posted June 12, 2010 Share Posted June 12, 2010 Here's what's returned in the browser: <?xml version="1.0" encoding="UTF-8"?> <hmm status="ok"> <player-command> <command>volume</command> <value>179</value> <value2>0</value2> <value3></value3> </player-command> </hmm> Ken PHP will throw a syntax error resulting in a blank page if error's are turned off and I assume they are as he doesn't tell us about any error. As PHP sees it as $hmm1->player - command where command is assumed to be a constant. Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071216 Share on other sites More sharing options...
kenrbnsn Posted June 12, 2010 Share Posted June 12, 2010 In your other problem you used the class SimpleXMLElement. Why aren't you using that here? Ken Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071218 Share on other sites More sharing options...
flemingmike Posted June 12, 2010 Author Share Posted June 12, 2010 there isnt any errors. here is my whole page code. everything works except for the getvolume. the spot for '.$vol.' is just an empty field. <?php include("style.php"); $hmm1 = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getvolume'); foreach ($hmm1->player-command as $volume1) { $vol = $volume1->value; } $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.GetNowPlayingData'); foreach ($hmm->tracks as $tracks) { $artist = $tracks->track->artist; $title = $tracks->track->title; $album = $tracks->track->album; } 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); 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="4" 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="4" 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>'.$vol.'</td> </tr> <tr> <td align="center" width="87"><b>Album:</b></td> <td>'.$album.'</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"> <img border="0" src="images/Button-Delete-icon.bmp" width="64" height="64"></td> <td align="center" width="20%"><font size="5">Volume</font></td> <td align="center"> <img border="0" src="images/Button-Add-icon.bmp" width="64" height="64"></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 https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071220 Share on other sites More sharing options...
kenrbnsn Posted June 12, 2010 Share Posted June 12, 2010 I believe the problem is being caused by the string 'player-command', since the '-' is being interpreted as minus sign. Try: <?php $x = 'player-command'; $vol = $hmm1->$x->value; ?> You don't need the "foreach" since there is only one record being returned. Ken Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071225 Share on other sites More sharing options...
flemingmike Posted June 12, 2010 Author Share Posted June 12, 2010 thank you sooo much ken. i cant believe i never figured that out.!! Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071228 Share on other sites More sharing options...
flemingmike Posted June 12, 2010 Author Share Posted June 12, 2010 ok, now i feel just dumb. this would be so much easier in vb. so my code is now: $hmm1 = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getvolume'); $x = 'player-command'; $vol = $hmm1->$x->value; $volup = $hmm1->$x->value +50; $voldown = $hmm1->$x->value -50; but how can i refresh the value after going up or down? it keeps the existing value from when the page originally loaded. here is my current link: http://www.durhamit.ca:8181/1.0/?method=player.setvolume&volume='.$voldown.' Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071229 Share on other sites More sharing options...
ignace Posted June 12, 2010 Share Posted June 12, 2010 I believe the problem is being caused by the string 'player-command', since the '-' is being interpreted as minus sign. Try: <?php $x = 'player-command'; $vol = $hmm1->$x->value; ?> You don't need the "foreach" since there is only one record being returned. Ken Really?? LOL told you like 2 hours ago Link to comment https://forums.phpfreaks.com/topic/204586-why-doesnt-this-work/#findComment-1071243 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.