Webbased control interface (Problem with JSON-RPC function)
#1
Hi all,
I'm making an internal website on my media server that controls all my xbmc endpoints in the house (a raspberry pi connected to the network in each room)
To do this, I'm coding it in PHP, and have been reading up on the V6 JSON-RPC api

All works fine, except the Player.Open function.Play function

My code:
Code:
    /* Play snippit */
    public function play(){
        $endpoint = new XbmcEndpoint(array(    'endpoint_address' => '***.***.***.***','endpoint_port' => '****','endpoint_user' => '****','endpoint_pass' => '****'    ));
        $episode = $endpoint->getEpisodeDetails(array('episodeid' => (int)(Request::getGetParameter('eid')), 'properties' => array('file')));
        $result = $endpoint->play(array('item' => array('file' => $episode->file)));
    }

    /* XbmcEndpoint snippit */
    public function getEpisodeDetails($params){
        if(!$this->_validate()) return false;
        $this->_deploy(array('jsonrpc' => '2.0', 'method' => 'VideoLibrary.GetEpisodeDetails', 'id' => '1', 'params' => $params));
        return isset($this->result->result) && isset($this->result->result->episodedetails) ? $this->result->result->episodedetails : $this->result;
    }
    
    public function play($params){
        if(!$this->_validate()) return false;
        $this->_deploy(array('jsonrpc' => '2.0', 'method' => 'Player.Open', 'id' => '1', 'params' => $params));
        return isset($this->result->result) && isset($this->result->result->episodes) ? $this->result->result->episodes : $this->result;
    }
    
    protected function _validate(){
        if($this->endpoint_address !== null && $this->endpoint_port !== null) return true;
        return false;
    }
    
    protected function _deploy($json){
        $response = CURL::get(sprintf('http://%s:%s@%s:%s/%s%s',$this->endpoint_user,$this->endpoint_pass,$this->endpoint_address,$this->endpoint_port,$this->query,json_encode($json)),  array(),'',$this->add_headers);
        $this->result = json_decode($response['content']);
    }

A little explenation of the code.
I pass a episodeid to a page, it loads the details (this works)
retrieves the file location which is something like "nfs://***.***.***.***/export/Series/Futurama/Specials/Futurama - s00e02 - The Beast With A Billion Backs.avi"
and passes it to the api to play

The result I get is:
Code:
stdClass Object
(
    [error] => stdClass Object
        (
            [code] => -32700
            [message] => Parse error.
        )

    [id] =>
    [jsonrpc] => 2.0
)

anyone who can help me?

Edit: made title more clear
Reply
#2
Something wrong with the JSON. Best to output what you are trying to send.
Image
AWXi - Ajax web interface. Wiki
Reply
#3
I made a "dump" of the url that is called:

http://****:****@***.***.***.***:****/jsonrpc?request={"jsonrpc":"2.0","method":"Player.Open","id":"1","params":{"item":{"file":"nfs:\/\/***.***.***.***\/export\/Series\/Blue Bloods\/Blue.Bloods.S01E12.HDTV.XviD-LOL.avi"}}}

Strange thing is, if I run this url with php CURL class, it returns the error
if I run it with my browser (paste te url) it does work... => ({"id":"1","jsonrpc":"2.0","result":"OK"})
Reply
#4
That request doesn't look URL encoded to me Wink http://wiki.xbmc.org/index.php?title=JSON-RPC_API#GET
Your browser URL encodes it for you.
Image
AWXi - Ajax web interface. Wiki
Reply
#5
Fantastic, You helped me solve it.
Reply

Logout Mark Read Team Forum Stats Members Help
Webbased control interface (Problem with JSON-RPC function)0