2011-08-13, 02:08
Hello,
I apologise in advance if I ask any stupid questions - you might gather from the number of posts I've made on this forum that I'm a bit new to all this ;-)
I feel that I'm close to knowing what I need to do having read this thread ... can someone confirm - or prod me in the right direction if not?
I want my XBMC (on linux) to start playing my favourite radio station when I press a shortcut button on my mobile phone.
From what I read on this thread I have to:
1. Make sure my (linux) XBMC server side is all set up and ready to receive JSON RPC
2. Set up a server side streaming file for XBMC to play - containing the web address of the radio stream. I've called it ~/arctic/antenne_bayern.strm
3. Now - this is the bit I'm still a bit unsure about how to do ...
I want to initiate a command to my XBMC from my phone. I don't want to use a remote control app - I want to have a single shortcut icon that I only have to tap once from my home screen - or trigger by any number of other amusing ways using a great app called tasker that I found .
It seems there are plenty of ways of getting a message to an XBMC server - but can I initiate a POST request simply by the act of loading a webpage? By invoking a javascript function when the page loads?
Can this POST message people are talking about above be kicked off from a bit of javascript - or ajax? If this is true then all I have to do is make a shortcut to the webpage on the home screen of my phone - hit the shortcut and off it goes then I don't need to mess about trying to find mobile versions of various script interpreters ...
3a. So assuming all that is possible: Will a phone browser be able to deal with AJAX in an html file? Will my XBMC server want a username and password first? Will that stop this from working?
What do I need to write in my javascript function to get XBMC to start playing my file?
Here is my guess having read this thread and your wiki - apologies if it seems obvious to everyone else, but I'm new any help greatly appreciated.
So - there is my first hair-brained scheme - does this look like it might work? or is there an easier way to fire off a POST request from a smart phone? Bearing in mind that I need it to be a one shot execution - so I can play with how I kick it off later!
I apologise in advance if I ask any stupid questions - you might gather from the number of posts I've made on this forum that I'm a bit new to all this ;-)
I feel that I'm close to knowing what I need to do having read this thread ... can someone confirm - or prod me in the right direction if not?
I want my XBMC (on linux) to start playing my favourite radio station when I press a shortcut button on my mobile phone.
From what I read on this thread I have to:
1. Make sure my (linux) XBMC server side is all set up and ready to receive JSON RPC
2. Set up a server side streaming file for XBMC to play - containing the web address of the radio stream. I've called it ~/arctic/antenne_bayern.strm
3. Now - this is the bit I'm still a bit unsure about how to do ...
I want to initiate a command to my XBMC from my phone. I don't want to use a remote control app - I want to have a single shortcut icon that I only have to tap once from my home screen - or trigger by any number of other amusing ways using a great app called tasker that I found .
It seems there are plenty of ways of getting a message to an XBMC server - but can I initiate a POST request simply by the act of loading a webpage? By invoking a javascript function when the page loads?
Can this POST message people are talking about above be kicked off from a bit of javascript - or ajax? If this is true then all I have to do is make a shortcut to the webpage on the home screen of my phone - hit the shortcut and off it goes then I don't need to mess about trying to find mobile versions of various script interpreters ...
3a. So assuming all that is possible: Will a phone browser be able to deal with AJAX in an html file? Will my XBMC server want a username and password first? Will that stop this from working?
What do I need to write in my javascript function to get XBMC to start playing my file?
Here is my guess having read this thread and your wiki - apologies if it seems obvious to everyone else, but I'm new any help greatly appreciated.
Code:
<html>
<head>
<script>
function XbmcPlayFile()
{
var data = '{"jsonrpc": "2.0", "method": "XBMC.Play", "params": { "file": "/home/arctic/antenne_bayern.strm"}, "id": 1}' http://myIPaddress:9019/jsonrpc;
var xhr;
xhr = new XMLHttpRequest(); // for an Opera like mobile browser?
xhr.onreadystatechange = function()
{
// do something with xhr.responseText;
};
xhr.open("POST", "ajax-post-response-text.php", true, myLogin, myPassword);
// line below is for a form - do I bother with this - what's it need to be?
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(data);}
</script>
</head>
<body>
<script type="text/javascript" language="JavaScript">
XbmcPlayFile();
</script>
</body>
</html>
So - there is my first hair-brained scheme - does this look like it might work? or is there an easier way to fire off a POST request from a smart phone? Bearing in mind that I need it to be a one shot execution - so I can play with how I kick it off later!