PDA

View Full Version : Best way to create little web interface



Hydro
2014-05-09, 08:03
Hi

I like logitech media server, very usefull and many possiblity to use it.

I'm creating website for my home automation and i want to use some LMS function inside.

Basically i want :

1 - Retreive library to show album / artiste / song on my html website.

2 - Add basic buttons : play / pause / next ...

3 - Select player and maybe add sync fuction

For the moment i'm at step 1. I try to retreive library with json / curl php. So now i've got array with all album.
I see that some users use library.db from LMS, is it better than json request for my purpose ?


For step 2 i think http request with informations from step 1 is good ?

Thank for your answers.

(Sorry for my bad english)

Roland0
2014-05-09, 09:32
Basically i want :

1 - Retreive library to show album / artiste / song on my html website.

2 - Add basic buttons : play / pause / next ...

3 - Select player and maybe add sync fuction



Have a look at the SqueezeJS (http://wiki.slimdevices.com/index.php/SqueezeJS_tutorial) framework, which has pre-build components for your use cases (and more).



I see that some users use library.db from LMS, is it better than json request for my purpose ?

No

Hydro
2014-05-10, 05:22
Thank for your answers. I start to look at squeezejs but i'm not very good with JavaScript.

I see that you have developed an alternative interface. Do you use squeezejs to ?

Maybe I will have some questions to know how retrieve library informations.

Roland0
2014-05-11, 07:02
I see that you have developed an alternative interface. Do you use squeezejs to ?

Only a small part of it (modified SqueezeJS.Controller, SonginfoParser and PlayerChooser)

Hydro
2014-05-13, 02:25
Ok i try to take a look at your code but i don't understand eveything :D

First step, how do you retrieve library ?

Hydro
2014-05-13, 05:29
I try to retreive data with json :


$json_data = '{"id":1,"method":"slim.request","params":[ "", ["albums", "0","50" ]]}';

$post = file_get_contents('http://172.16.10.153:9000/jsonrpc.js',null,stream_context_create(array(
'http' => array(
'protocol_version' => 1.1,
'user_agent' => 'PHPExample',
'method' => 'POST',
'header' => "Content-type: application/json\r\n".
"Connection: close\r\n" .
"Content-length: " . strlen($json_data) . "\r\n",
'content' => $json_data,
),
)));


$array = json_decode($post);
print_r($array);

I've got this response :


stdClass Object ( [params] => Array ( [0] => [1] => Array ( [0] => albums [1] => 0 [2] => 50 ) ) [method] => slim.request [id] => 1 [result] => stdClass Object ( [count] => 2 [albums_loop] => Array ( [0] => stdClass Object ( [album] => Pas d'album [id] => 1 ) [1] => stdClass Object ( [album] => Random Access Memories [id] => 2 ) ) ) )


but i don't know how to put that on mysql ?

I try that but not working :


$dbhost = '172.16.10.2';
$dbuser = 'root';
$dbpass = 'root';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);

mysql_select_db( "squeeze" );

$sql = "
INSERT INTO album (id, nom)
VALUES ('1', ':album')
";
$stmt = $pdo->prepare($sql);
if($stmt == false) {
throw new Exception(print_r($pdo->errorInfo,1).PHP_EOL.$sql);
}
foreach($array as $data) {
$values = array(
':album' => $data['album']
);
if($stmt->execute($values) == false) {
throw new Exception(print_r($stmt->errorInfo(),1).PHP_EOL.$sql);
}
}

mysql_close($conn);

Roland0
2014-05-15, 15:41
First step, how do you retrieve library ?

Have a look at the SlimGrid*All* classes.
Not sure why you want to do this for your use cases, though.

Roland0
2014-05-15, 15:58
I try to retreive data with json :

So you decided to follow the PHP route and not use SqueezeJS. Understandable if you know PHP....



I've got this response :
but i don't know how to put that on mysql ?

or maybe you don't really....

Anyway, I don't quite see what you are even trying to accomplish - copying data from one DB to another? What for?



I try that but not working :

Looks like you are not accessing the data structure ($array) correctly.
However, this is obviously a PHP issue, so you might want to ask this question on an appropriate forum (which this is imo not), and actually include relevant information (not only "but not working")

Hydro
2014-07-04, 07:44
Thank for your answer.

Is it possible to subscribe to player statut with html 5 web stocket ?

Roland0
2014-07-09, 06:51
Is it possible to subscribe to player statut with html 5 web stocket ?
No, but you can use comet instead

Hydro
2014-09-12, 07:01
I try to find a way to use comet with logitech media server but nothing found :(

Basicaly just need subscribe to player status for example and do a http request to send the value.

mherger
2014-09-14, 05:14
> I try to find a way to use comet with logitech media server but nothing
> found :(

In a web UI? Or what programming language?

pippin
2014-09-14, 05:24
There is one thread here in the developers forum which describes how it works. Maybe Google helps if forum search doesn't.

Hydro
2014-09-15, 00:31
I want to subscribe to player events to update my own web interface. For now I refresh player info with json request but I want to use subscribe.

Even with google I can't find thread. Most links in posts are dead.

mherger
2014-09-15, 06:18
> I want to subscribe to player events to update my own web interface. For
> now I refresh player info with json request but I want to use
> subscribe.

Unless you can give us more information how you're trying to achieve
this noble goal, we won't be able to help you much. Is this
communication going to happen from a web page or the web server? The
first most likely will fail due to security limitations in the browser:
you can't talk to an other web server than where you loaded your page
from (there are some ways around this, but that's an advanced topic). If
you want the server to talk to your LMS then it might be interesting to
know what kind of server you plan to use.

--

Michael

Hydro
2014-09-15, 08:17
Ok my setup now :

Wamp server with html page that send every 5 sec a json request and update result like curent song.

What i'm looking for :

Wamp server with html page (if compatible with comet language) that update result when something change on player, no more refresh every x secondes.

mherger
2014-09-15, 21:04
> Wamp server with html page that send every 5 sec a json request and
> update result like curent song.

I'm surprised this works at all.

FWIW: I haven't seen any comet implementation in JS in these forums yet.
Polling probably is the way to go unless you want to do some pioneering
work.

--

Michael

Hydro
2014-09-16, 00:22
I'm surprised this works at all.



My way to get current song ?


I'm not very good to develop something like this. I thought there was an easy way to subscribe to player and display informations into html page :( Maybe with JS but can we get all informations like subscribe function ?

mherger
2014-09-16, 00:26
> I'm not very good to develop something like this. I thought there was an
> easy way to subscribe to player and display informations into html page
> :( Maybe with JS but can we get all informations like subscribe function

No, you can't subscribe using JS.

--

Michael

Hydro
2014-09-16, 00:34
Yep but i can use it to retrieve current title in real time no ?

I don't know how squeezeJS works, polling ?

mherger
2014-09-16, 01:12
> Yep but i can use it to retrieve current title in real time no ?

No, real time would require comet and a subscription to status updates -
which you currently can't do. Unless you find a JS implementation of comet.

> I don't know how squeezeJS works, polling ?

Yes, it's polling.

--

Michael

Hydro
2014-09-16, 06:08
Maybe it's possible with telnet ?

Hydro
2014-09-17, 02:18
I think best way is to create a LMS plugin that send http request to an API every time something happen.