JSON web interface

Discussion about configuration and usage of VLM (a stream scheduler) within VLC.
vice
Blank Cone
Blank Cone
Posts: 61
Joined: 18 Oct 2007 13:43

JSON web interface

Postby vice » 10 Jun 2008 16:56

I don't know if it could be of interest, but as part of a project that I'm developing that uses the VLC media player as a very important piece, I write a file for the web interface that export the information of VLM elements to JSON (like vlm.xml do in XML).

The second file, is a JSONP adaptation to test the functionality without need to put some infraestructure to avoid Cross Domain Request.

Doing so, I spot some rough points that perhaps could be resolved:

1. I name the files html to take advantages of the VLC parser. Could it be posible to include others extension to the parsed files (like .json or even .jsonp) in the web interface directories.
2. "enabled" and "loop" use "yes" and "no" as values, and in "instances" "seekable" has "0" or "1" as values. This is inconsistent, I think. Pehaps change both to use "true" and "false" as values could be a good idea. This way, the values could be converted to JSON boolean directly.
3. Documentation in HowTo/Building Pages for the HTTP Interface (http://wiki.videolan.org/Documentation: ... _Interface) is not complete. I don't know how much is left but there's no mention to vlm local variable for example. I need to figure out seeing the code.

Hope you consider those changes and the inclusion of those files in the "requests" directory.

vlm.json.html:

Code: Select all

<vlc id="if" param1="0"/> <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > < vlm.jsonp.html: VLC media player web interface < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > < Copyright (C) 2008 the VideoLAN team < < Authors: Vicente Jimenez Aguilar (based on vlm.xml by Antoine Cellerier) < < This program is free software; you can redistribute it and/or modify < it under the terms of the GNU General Public License as published by < the Free Software Foundation; either version 2 of the License, or < (at your option) any later version. < < This program is distributed in the hope that it will be useful, < but WITHOUT ANY WARRANTY; without even the implied warranty of < MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the < GNU General Public License for more details. < < You should have received a copy of the GNU General Public License < along with this program; if not, write to the Free Software < Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> <vlc id="end"/> { <vlc id="foreach" param1="el" param2="vlm" /> <vlc id="if" param1="el.type value 'broadcast' strcmp 0 =" /> "vlmElement<vlc id="value" param1="el.name"/>": { "type": "broadcast", "name": "<vlc id="value" param1="el.name"/>", "enabled": "<vlc id="value" param1="el.enabled" />", "loop": "<vlc id="value" param1="el.loop"/>", "output": "<vlc id="value" param1="el.output" />", "inputs": [ <vlc id="foreach" param1="in" param2="el.inputs" /> "<vlc id="value" param1="in" />", <vlc id="end" /> ], "options": [ <vlc id="foreach" param1="opt" param2="el.options" /> "<vlc id="value" param1="opt" />", <vlc id="end" /> ], "instances": [ <vlc id="foreach" param1="inst" param2="el.instances" /> { "name": "<vlc id="value" param1="inst.name"/>", "state": "<vlc id="value" param1="inst.state"/>", "position": <vlc id="value" param1="inst.position"/>, "time": <vlc id="value" param1="inst.time"/>, "length": <vlc id="value" param1="inst.length"/>, "rate": <vlc id="value" param1="inst.rate"/>, "title": "<vlc id="value" param1="inst.title"/>", "chapter": "<vlc id="value" param1="inst.chapter"/>", "seekable": "<vlc id="value" param1="inst.seekable"/>", "playlistindex": <vlc id="value" param1="inst.playlistindex"/> } <vlc id="end" /> ] }, <vlc id="else" /> <vlc id="if" param1="el.type value 'vod' strcmp 0 =" /> "vlmElement<vlc id="value" param1="el.name"/>": { "type": "vod", "name": "<vlc id="value" param1="el.name"/>", "enabled": "<vlc id="value" param1="el.enabled" />", "output": "<vlc id="value" param1="el.output" />", "inputs": [ <vlc id="foreach" param1="in" param2="el.inputs" /> "<vlc id="value" param1="in" />", <vlc id="end" /> ], "options": [ <vlc id="foreach" param1="opt" param2="el.options" /> "<vlc id="value" param1="opt" />", <vlc id="end" /> ], "instances": [ <vlc id="foreach" param1="inst" param2="el.instances" /> { "name": "<vlc id="value" param1="inst.name"/>", "state": "<vlc id="value" param1="inst.state"/>", "position": <vlc id="value" param1="inst.position"/>, "time": <vlc id="value" param1="inst.time"/>, "length": <vlc id="value" param1="inst.length"/>, "rate": <vlc id="value" param1="inst.rate"/>, "title": "<vlc id="value" param1="inst.title"/>", "chapter": "<vlc id="value" param1="inst.chapter"/>", "seekable": "<vlc id="value" param1="inst.seekable"/>", "playlistindex": <vlc id="value" param1="inst.playlistindex"/> } <vlc id="end" /> ] }, <vlc id="else" /> "vlmElement<vlc id="value" param1="el.name"/>": { "type": "schedule", "name": "<vlc id="value" param1="el.name"/>", "enabled": "<vlc id="value" param1="el.enabled" />", "date": "<vlc id="value" param1="el.date"/>", "period": "<vlc id="value" param1="el.period"/>", "repeat": "<vlc id="value" param1="el.repeat"/>", "commands": [ <vlc id="foreach" param1="com" param2="el.commands" /> "<vlc id="value" param1="com" />", <vlc id="end" /> ], }, <vlc id="end" /> <vlc id="end" /> <vlc id="end" /> }
vlm.jsonp.html:

Code: Select all

<vlc id="if" param1="0"/> <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > < vlm.json.html: VLC media player web interface < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > < Copyright (C) 2008 the VideoLAN team < < Authors: Vicente Jimenez Aguilar (based on vlm.xml by Antoine Cellerier) < < This program is free software; you can redistribute it and/or modify < it under the terms of the GNU General Public License as published by < the Free Software Foundation; either version 2 of the License, or < (at your option) any later version. < < This program is distributed in the hope that it will be useful, < but WITHOUT ANY WARRANTY; without even the implied warranty of < MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the < GNU General Public License for more details. < < You should have received a copy of the GNU General Public License < along with this program; if not, write to the Free Software < Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> <vlc id="end"/> <vlc id="if" param1="url_param 1 =" /> <vlc id="value" param1="; 'jsonp' url_extract" />( { <vlc id="foreach" param1="el" param2="vlm" /> <vlc id="if" param1="el.type value 'broadcast' strcmp 0 =" /> "vlmElement<vlc id="value" param1="el.name"/>": { "type": "broadcast", "name": "<vlc id="value" param1="el.name"/>", "enabled": "<vlc id="value" param1="el.enabled" />", "loop": "<vlc id="value" param1="el.loop"/>", "output": "<vlc id="value" param1="el.output" />", "inputs": [ <vlc id="foreach" param1="in" param2="el.inputs" /> "<vlc id="value" param1="in" />", <vlc id="end" /> ], "options": [ <vlc id="foreach" param1="opt" param2="el.options" /> "<vlc id="value" param1="opt" />", <vlc id="end" /> ], "instances": [ <vlc id="foreach" param1="inst" param2="el.instances" /> { "name": "<vlc id="value" param1="inst.name"/>", "state": "<vlc id="value" param1="inst.state"/>", "position": <vlc id="value" param1="inst.position"/>, "time": <vlc id="value" param1="inst.time"/>, "length": <vlc id="value" param1="inst.length"/>, "rate": <vlc id="value" param1="inst.rate"/>, "title": "<vlc id="value" param1="inst.title"/>", "chapter": "<vlc id="value" param1="inst.chapter"/>", "seekable": "<vlc id="value" param1="inst.seekable"/>", "playlistindex": <vlc id="value" param1="inst.playlistindex"/> } <vlc id="end" /> ] }, <vlc id="else" /> <vlc id="if" param1="el.type value 'vod' strcmp 0 =" /> "vlmElement<vlc id="value" param1="el.name"/>": { "type": "vod", "name": "<vlc id="value" param1="el.name"/>", "enabled": "<vlc id="value" param1="el.enabled" />", "output": "<vlc id="value" param1="el.output" />", "inputs": [ <vlc id="foreach" param1="in" param2="el.inputs" /> "<vlc id="value" param1="in" />", <vlc id="end" /> ], "options": [ <vlc id="foreach" param1="opt" param2="el.options" /> "<vlc id="value" param1="opt" />", <vlc id="end" /> ], "instances": [ <vlc id="foreach" param1="inst" param2="el.instances" /> { "name": "<vlc id="value" param1="inst.name"/>", "state": "<vlc id="value" param1="inst.state"/>", "position": <vlc id="value" param1="inst.position"/>, "time": <vlc id="value" param1="inst.time"/>, "length": <vlc id="value" param1="inst.length"/>, "rate": <vlc id="value" param1="inst.rate"/>, "title": "<vlc id="value" param1="inst.title"/>", "chapter": "<vlc id="value" param1="inst.chapter"/>", "seekable": "<vlc id="value" param1="inst.seekable"/>", "playlistindex": <vlc id="value" param1="inst.playlistindex"/> } <vlc id="end" /> ] }, <vlc id="else" /> "vlmElement<vlc id="value" param1="el.name"/>": { "type": "schedule", "name": "<vlc id="value" param1="el.name"/>", "enabled": "<vlc id="value" param1="el.enabled" />", "date": "<vlc id="value" param1="el.date"/>", "period": "<vlc id="value" param1="el.period"/>", "repeat": "<vlc id="value" param1="el.repeat"/>", "commands": [ <vlc id="foreach" param1="com" param2="el.commands" /> "<vlc id="value" param1="com" />", <vlc id="end" /> ], }, <vlc id="end" /> <vlc id="end" /> <vlc id="end" /> }) <vlc id="end" />

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: JSON web interface

Postby Jean-Baptiste Kempf » 10 Jun 2008 19:04

Demo ?
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

vice
Blank Cone
Blank Cone
Posts: 61
Joined: 18 Oct 2007 13:43

Re: JSON web interface

Postby vice » 11 Jun 2008 10:44

Put those 2 files in the requests directory inside the directory of the web interface (platform dependant). And activating the web interface.

Configuring VLC media player, for example with those VLM commands:

Code: Select all

new BroadcastTest broadcast enabled loop setup BroadcastTest input "C:\local\VideoTests\CamaraBN00.mp4" setup BroadcastTest output #rtp{dst=224.1.2.3,port=1234,sdp=rtsp://localhost/test.sdp} setup BroadcastTest option sout-keep new VodText vod enabled setup VodText input "C:\local\VideoTests\CamaraBN01.mp4" setup VodText input "C:\local\VideoTests\CamaraBN02.mp4" new ScheduleTest schedule date 2007/12/1-0:59:59 disabled setup ScheduleTest append control play BroadcastTest control BroadcastTest play
Directing the browser to http://localhost:8080/requests/vlm.xml we have the following output:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <vlm> <broadcast name="BroadcastTest" enabled="yes" loop="yes"> <output>#rtp{dst=224.1.2.3,port=1234,sdp=rtsp://localhost/test.sdp}</output> <inputs> <input>C:\local\VideoTests\CamaraBN00.mp4</input> </inputs> <options> <option>sout-keep</option> </options> <instances> </instances> </broadcast> <vod name="VodText" enabled="yes"> <output></output> <inputs> <input>C:\local\VideoTests\CamaraBN01.mp4</input> <input>C:\local\VideoTests\CamaraBN02.mp4</input> </inputs> <options> </options> <instances> </instances> </vod> <schedule name="ScheduleTest" enabled="no" date="2007/12/1-0:59:59" period="0" repeat="-1"> <commands> <command>control play BroadcastTest</command> </commands> </schedule> </vlm>
This output to be used by javascript you need to parse the XML and that is resourse intensive for doing in JavaScript.
Instead, requesting http://localhost:8080/requests/vlm.json.html, the output is:

Code: Select all

{ "vlmElementBroadcastTest": { "type": "broadcast", "name": "BroadcastTest", "enabled": "yes", "loop": "yes", "output": "#rtp{dst=224.1.2.3,port=1234,sdp=rtsp://localhost/test.sdp}", "inputs": [ "C:\local\VideoTests\CamaraBN00.mp4", ], "options": [ "sout-keep", ], "instances": [ { "name": "default", "state": "playing", "position": 0.070064, "time": 2200000, "length": 31400000, "rate": 1000, "title": "0", "chapter": "0", "seekable": "1", "playlistindex": 1 } ] }, "vlmElementVodText": { "type": "vod", "name": "VodText", "enabled": "yes", "output": "", "inputs": [ "C:\local\VideoTests\CamaraBN01.mp4", "C:\local\VideoTests\CamaraBN02.mp4", ], "options": [ ], "instances": [ ] }, "vlmElementScheduleTest": { "type": "schedule", "name": "ScheduleTest", "enabled": "no", "date": "2007/12/1-0:59:59", "period": "0", "repeat": "-1", "commands": [ "control play BroadcastTest", ], }, }
For JavaScript this is an anonymous object that containts 3 objects named vlmElement<name of the vlm element> (this is a personal decision), in this case:
  • vlmElementBroadcastTest
    vlmElementVodTest
    vlmElementScheduleTest
Normally you asign the response to a variable so you end with an object variable that containt all the VLM elements as objects. Assume that you asign this http response to the httpResponse variable. You can use any information in the response using this notation:
httpResponse.vlmElementBroadcastTest.inputs[0] will return the first input of the VLM element named BroadcastTest (httpResponse.vlmElementBroadcastTest.name).

The decision to make a convention to name every object returned, instead of doing an array of anonymous object is because for my project I just need to control 2 VLM elements and if I presume they always named exactly the same y can use then directly without needing to search for those names in all the array of objects.

vice
Blank Cone
Blank Cone
Posts: 61
Joined: 18 Oct 2007 13:43

Re: JSON web interface

Postby vice » 11 Jun 2008 11:01

Secondly,

This data type is only useful if you want it to use in the JavaScript code served by the VLC web server interface.

My project's application is going to be served by a proper web server so we hit the cross domain request protection.

We surely going to overcome this limitation by setting a directory to doing some relay. But this is too much for just some testing that I doing now. This is the reason of the second file: vlm.jsonp.html.

JSONP is a technique to overcome the cross site request limitation by requesting a script. usually the response is a function with the response as an argument. What is interesting about JSONP is that you send in your request the name of the function that you want. So you decide the name of the function in the request and the arguments of this function is the response. In this case the response of VLC media player.

With the same configuration has above, the response to the request http://localhost:8080/requests/vlm.json ... ckFunction was:

Code: Select all

CallBackFunction( { "vlmElementBroadcastTest": { "type": "broadcast", "name": "BroadcastTest", "enabled": "yes", "loop": "yes", "output": "#rtp{dst=224.1.2.3,port=1234,sdp=rtsp://localhost/test.sdp}", "inputs": [ "C:\local\VideoTests\CamaraBN00.mp4", ], "options": [ "sout-keep", ], "instances": [ { "name": "default", "state": "playing", "position": 0.515924, "time": 16200000, "length": 31400000, "rate": 1000, "title": "0", "chapter": "0", "seekable": "1", "playlistindex": 1 } ] }, "vlmElementVodText": { "type": "vod", "name": "VodText", "enabled": "yes", "output": "", "inputs": [ "C:\local\VideoTests\CamaraBN01.mp4", "C:\local\VideoTests\CamaraBN02.mp4", ], "options": [ ], "instances": [ ] }, "vlmElementScheduleTest": { "type": "schedule", "name": "ScheduleTest", "enabled": "no", "date": "2007/12/1-0:59:59", "period": "0", "repeat": "-1", "commands": [ "control play BroadcastTest", ], }, })
Notice that the name of the function was sended in the resquest as the value of the jsonp attribute (another personal decision).

This way (requesting dinamically scripts), you can do requests from the browser to a different domain (address or port).
I use it to do some test without needing to set a relay server or load the little VLC server with a lot of application files.
Last edited by vice on 11 Jun 2008 11:24, edited 2 times in total.

vice
Blank Cone
Blank Cone
Posts: 61
Joined: 18 Oct 2007 13:43

Re: JSON web interface

Postby vice » 11 Jun 2008 11:18

And finally, for the real demos.
I use the dojo toolkit, so those examples are going to be especific to this framework. Is for that reason that I've try to explain the theory in the other 2 post above.

For the normal XmlHttpRequest

Code: Select all

function getVlcInfo(){ dojo.xhrGet({ url: "http://localhost:8080/requests/vlm.json.html", handleAs: "json", timeout: 5000, load: function(response, ioArgs){ console.log(response); return response; }, error: function(response, ioArgs){ console.error("HTTP status code: ", ioArgs.xhr.status); console.error(response); return response; } }); },


Again, remenber that if the javascript code is served by a different server that the one you request, you going to hit against the cross domain request security policy of the browser. The request fail for security reasons.

So you can do this instead:

Code: Select all

function getVlcInfoByJsonp:(){ dojo.io.script.get({ url: "http://localhost:8080/requests/vlm.jsonp.html", callbackParamName: "jsonp", timeout: 5000, load: function(response, ioArgs){ console.log(response); return response; }, error: function(response, ioArgs){ console.error("HTTP status code: ", ioArgs.xhr.status); console.error(response); return response; } }); },
Notice that we need to tell what parameter is use to transmit the name of the callback function. The dojo Toolkit use their own callback function that handle the response and if the answer is correct it execute the function defined or putted in load as above.

Both example only log the response, but you can do wathever you need with this information using it directly as JavaScript objects.

vice
Blank Cone
Blank Cone
Posts: 61
Joined: 18 Oct 2007 13:43

Re: JSON web interface

Postby vice » 11 Jun 2008 11:33

Others framework examples welcome :wink:

You can also do the request directly. But javaScript frameworks (like dojo toolkit, prototype, jQuery, etc) hide a lot of dificulties, like browser diferences.

vice
Blank Cone
Blank Cone
Posts: 61
Joined: 18 Oct 2007 13:43

Re: JSON web interface

Postby vice » 11 Jun 2008 13:39

More information about the JSON standard:

vice
Blank Cone
Blank Cone
Posts: 61
Joined: 18 Oct 2007 13:43

Re: JSON web interface

Postby vice » 11 Jun 2008 13:46

Similarly, for sending the VLM commands and have the response in JSON, I've created the file vlm_cmd.json.html (the extension html again is for activate the VLC media player parser).

Code: Select all

<vlc id="if" param1="0"/> <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > < vlm_cmd.json.html: VLC media player web interface < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > < Copyright (C) 2008 the VideoLAN team < < Authors: Vicente Jimenez Aguilar < Based on vlm_cmd.xml by Antoine Cellerier < < This program is free software; you can redistribute it and/or modify < it under the terms of the GNU General Public License as published by < the Free Software Foundation; either version 2 of the License, or < (at your option) any later version. < < This program is distributed in the hope that it will be useful, < but WITHOUT ANY WARRANTY; without even the implied warranty of < MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the < GNU General Public License for more details. < < You should have received a copy of the GNU General Public License < along with this program; if not, write to the Free Software < Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> <vlc id="end"/> <vlc id="if" param1="url_param 1 =" /> <vlc id="rpn" param1="; 'command' url_extract vlm_cmd" /> <vlc id="end" /> { "error": "<vlc id="value" param1="vlm_error" />" }
For the time being, the response was an object with only a string attribute named "error".

vice
Blank Cone
Blank Cone
Posts: 61
Joined: 18 Oct 2007 13:43

Re: JSON web interface

Postby vice » 11 Jun 2008 13:53

And for sending commands using the JSONP system (requesting a script):

vlm_cmd.jsonp.html:

Code: Select all

<vlc id="if" param1="0"/> <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > < vlm_cmd.jsonp.html: VLC media player web interface < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > < Copyright (C) 2008 the VideoLAN team < < Authors: Vicente Jimenez Aguilar < Based on vlm_cmd.xml by Antoine Cellerier < < This program is free software; you can redistribute it and/or modify < it under the terms of the GNU General Public License as published by < the Free Software Foundation; either version 2 of the License, or < (at your option) any later version. < < This program is distributed in the hope that it will be useful, < but WITHOUT ANY WARRANTY; without even the implied warranty of < MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the < GNU General Public License for more details. < < You should have received a copy of the GNU General Public License < along with this program; if not, write to the Free Software < Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> <vlc id="end"/> <vlc id="if" param1="url_param 1 =" /> <vlc id="rpn" param1="; 'command' url_extract vlm_cmd" /> <vlc id="value" param1="; 'jsonp' url_extract" />( { "error": "<vlc id="value" param1="vlm_error" />" }) <vlc id="end" />

scottw
New Cone
New Cone
Posts: 2
Joined: 28 Jan 2011 23:42

Re: JSON web interface

Postby scottw » 28 Jan 2011 23:45

For jQuery and JSONP:

Code: Select all

$.getJSON('http://192.168.1.10:8080/vlc_cmd.jsonp.html?callback=?', { command: "status" }, function(status){ alert( 'Status: ' + status.stream_state ); } );
On the VLC http server - vlc_cmd.jsonp.html :

Code: Select all

<vlc id="if" param1="0"/> <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > < vlm_cmd.jsonp.html: VLC media player web interface < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > < Based on vlm_cmd.xml by Antoine Cellerier < < This program is free software; you can redistribute it and/or modify < it under the terms of the GNU General Public License as published by < the Free Software Foundation; either version 2 of the License, or < (at your option) any later version. < < This program is distributed in the hope that it will be useful, < but WITHOUT ANY WARRANTY; without even the implied warranty of < MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the < GNU General Public License for more details. < < You should have received a copy of the GNU General Public License < along with this program; if not, write to the Free Software < Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> <vlc id="end"/> <vlc id="if" param1="url_param 1 =" /> <vlc id="rpn" param1="command 'command' url_extract store" /> <vlc id="rpn" param1="jsonp 'callback' url_extract store" /> <vlc id="rpn" param1="input 'input' url_extract store" /> <vlc id="if" param1="command value 'play' strcmp 0 =" /> <vlc id="rpn" param1="playlist_empty input value dup stripslashes playlist_add vlc_play" /> <vlc id="end" /> <vlc id="if" param1="command value 'stop' strcmp 0 =" /> <vlc id="rpn" param1="vlc_stop" /> <vlc id="end" /> <vlc id="if" param1="command value 'pause' strcmp 0 =" /> <vlc id="if" param1="stream_state value 'stop' strcmp 0 = id value 0 = ! &" /> <vlc id="rpn" param1="id value vlc_play"/> <vlc id="else" /> <vlc id="rpn" param1="vlc_pause" /> <vlc id="end" /> <vlc id="end" /> <vlc id="if" param1="command value 'volume' strcmp 0 =" /> <vlc id="rpn" param1="input value vlc_volume_set" /> <vlc id="end"/> <vlc id="if" param1="command value 'record' strcmp 0 =" /> <vlc id="rpn" param1="playlist_empty input value dup stripslashes playlist_add vlc_play" /> <vlc id="end"> <vlc id="if" param1="command value 'status' strcmp 0 =" /> <vlc id="end" /> <vlc id="value" param1="jsonp" />({ command: "<vlc id="value" param1="command" />", volume: "<vlc id="value" param1="volume" />", stream_state: "<vlc id="value" param1="stream_state" />", stream_position: "<vlc id="value" param1="stream_position" />", stream_length: "<vlc id="value" param1="stream_length" />", stream_time: "<vlc id="value" param1="stream_time" />" }) <vlc id="end" />

scottw
New Cone
New Cone
Posts: 2
Joined: 28 Jan 2011 23:42

browse.jsonp.html

Postby scottw » 02 Feb 2011 18:10

There's an extra new-line (or something) being returned by file.date, which this version trims off in order to not break the JSONP response. You can try it out in your fav' browser with something like: http://127.0.0.1:8080/browse.jsonp.html ... sonp&dir=c:/ - the jQuery usage would be similar to the previous post except you need to provide a { dir : 'c:/' } rather than { command : 'status' }

Code: Select all

<vlc id="if" param1="0"/> <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > < browse.jsonp.html: VLC media player web interface < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > < < Based on browse.xml code by: Antoine Cellerier <dionoea -at- videolan -dot- org> < < This program is free software; you can redistribute it and/or modify < it under the terms of the GNU General Public License as published by < the Free Software Foundation; either version 2 of the License, or < (at your option) any later version. < < This program is distributed in the hope that it will be useful, < but WITHOUT ANY WARRANTY; without even the implied warranty of < MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the < GNU General Public License for more details. < < You should have received a copy of the GNU General Public License < along with this program; if not, write to the Free Software < Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> <vlc id="end" /> <vlc id="if" param1="url_param 1 =" /> <vlc id="value" param1="'callback' url_extract" />({ files: [ <vlc id="rpn" param1="'dir' url_extract" /> <vlc id="foreach" param1="file" param2="directory" /> <vlc id="if" param1="file.basename value '.' 1 strncmp 0 != file.basename value '..' 2 strncmp 0 = |" /> { filetype: "<vlc id="value" param1="file.type" />", size: "<vlc id="value" param1="file.size" />", date: "<vlc id="value" param1="file.date value dup strlen 1 - 1 swap strsub" />", path: "<vlc id="value" param1="file.name value xml_encode" />", name: "<vlc id="value" param1="file.basename value xml_encode" />", extension: "<vlc id="value" param1="file.ext value xml_encode" />" }, <vlc id="end" /> <vlc id="end" /> <vlc id="end" /> ]})

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: JSON web interface

Postby Jean-Baptiste Kempf » 03 Feb 2011 16:53

What about adding this to VLC references code?
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.


Return to “VLM”

Who is online

Users browsing this forum: No registered users and 2 guests