You are not logged in.

#1 2010-11-07 14:30:27

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Controling VLC though RC

I've recently built a web based remote control for MPD for my phone. I want to do a similar thing with VLC but I'm having trouble finding a way to control vlc from my webserver. I know MPD used sockets and I also know a similar thing is possible for VLC using the rc interface but so far, I've found nothing but bad/no documentation and an outdated python script.

Anyone have any luck controlling VLC through sockets with the rc interface (or any other interface for that matter)?

Also, please don't suggest the http interface. It sucks. Hard. Unless I could skin it, but VLC uses some really strange methods for displaying it's web interface. This is also poorly documented.

Last edited by BaconPie (2010-11-07 14:31:23)

Offline

#2 2010-11-12 09:24:12

delwin
Member
Registered: 2010-06-21
Posts: 8

Re: Controling VLC though RC

You might take a look through this. I use the unix sockets interface to control vlc with hotkeys, so there might be a hint or two in here that you can make use of.

http://wiki.videolan.org/How_to_use_VLC … n_in_linux

Offline

#3 2010-11-12 13:44:32

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: Controling VLC though RC

Thanks for the script, it's awesome. But I still don't understand exactly how the sockets are working and how to use them with the PHP functions.

If someone could try explaining then that would be great.

Offline

#4 2010-11-12 14:21:02

delwin
Member
Registered: 2010-06-21
Posts: 8

Re: Controling VLC though RC

ah, i'm afraid i know buggerall about php. i just used nc.openbsd (needed to use openbsd's version of netcat for the -U option) to send the commands to the sockets.

Offline

#5 2010-11-12 14:23:04

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: Controling VLC though RC

Yeah, I read that in your script. So, what does it do? Write a value to vlc.sock using nc.openbsd and then vlc reads that file?

Offline

#6 2010-11-12 14:30:05

delwin
Member
Registered: 2010-06-21
Posts: 8

Re: Controling VLC though RC

yes, that's about it. pretty straightforward in the way i'm using it.

Offline

#7 2010-11-12 15:15:12

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: Controling VLC though RC

Ok, I think I'm getting somewhere:

$ vlc --extraintf rc --rc-host localhost:1234 video.avi
$ echo pause | nc.openbsd localhost 1234

Pauses the video.

Edit: This PHP pauses the video too! That's it I think. Don't know why I couldn't get any other shell_exec to work...

<?php
  shell_exec("echo pause | nc.openbsd localhost 1234");
?>

The only problem now is that it hangs waiting for another input. I have to type 'logout' to logout of the vlc interface.

Which means the php page just hangs waiting for a response. I've tried echoing a logout to the nc after but it doesn't reach that command because of the hang...

Edit2: The -w flag causes a logout after X seconds. It's less than desirable but it works.

Last edited by BaconPie (2010-11-12 15:45:15)

Offline

#8 2010-11-12 16:15:44

delwin
Member
Registered: 2010-06-21
Posts: 8

Re: Controling VLC though RC

try nc.openbsd -U localhost 1234, see if that fixes the problem

Offline

#9 2010-11-12 16:27:09

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: Controling VLC though RC

Nope. It didn't error, but it never did anything.

Offline

#10 2010-11-12 16:41:42

delwin
Member
Registered: 2010-06-21
Posts: 8

Re: Controling VLC though RC

Oh, of course it wouldn't. The -U switch works with unix sockets (which is why i had to use the openbsd version of netcat.) Sorry, i didn't see that you were using a port in your netcat string.

I didn't mess much with the other remote control interfaces, but for what it's worth, here's how i've got vlc set up:
(Tools->Preferences, click the 'all' radio button)

Interface->Main Interfaces, tick remote control interface, make sure the text box has 'oldrc' in it.

Expand Main Interfaces->RC, tick 'Show stream position' and 'Fake TTY', enter path for your socket (~/vlc.sock or what have you)

Dunno if that will be useful to you, but if you're just using it on your local machine, that might allow you to use -U and get the behaviour you're looking for.

Last edited by delwin (2010-11-12 16:42:22)

Offline

#11 2010-11-12 17:07:57

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: Controling VLC though RC

Yeah that's how I had it set up with your script and it worked perfectly. Only thing is, the user http can't run your script (at least through PHP anyway...).

I'm using nc.openbsd but without using a unix socket now and instead with a timeout of 1s. Like I said, it's not desirable but it works!

Thanks for the help.

I'll post the vlc.class.php code once I'm done. Maybe someone else can add improvements because it's going to be REALLY bad due to many factors, not least of which is that this is the first class I've wrote in php!

Last edited by BaconPie (2010-11-12 17:09:20)

Offline

#12 2010-11-12 17:42:31

delwin
Member
Registered: 2010-06-21
Posts: 8

Re: Controling VLC though RC

You'll manage. If I could cobble that python script together you can get this figured out. wink

I'm not quite sure what to make of your issue running the script. Provided the http user had permissions to execute it, I'd assume that it would work alright if you fed it /path/to/vlccontrol.py pause, but as I mentioned earlier, I know essentially nothing about php.

Hope you get it figured out.

Offline

#13 2010-11-13 18:14:21

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: Controling VLC though RC

Here is it. It's super nasty and broken but it sort of works.

<?php
/*
  VLC class
  Provides an interface to VLC media player which is easy to use.
  Version 0.1
  
  Notes:
  It's a little broken at the moment. It uses nc.openbsd to talk
  to the rc interface of vlc.
  
  We log into VLC and then either VLC or nc.openbsd waits for user input.
  Because of this I have to tell nc.openbsd to kill the conenction after
  1 second idle time. This means that any talking to vlc takes 1 second.
  
  With alot of chatter anything using this class takes a long time to load.
  
  It is less than acceptable but it works...
  
  ..except for the skipping. They don't because of currentTime() not returning
  anything at all sometimes so instead of skipping from now you skip from the
  start.

*/


class vlc
{
  var $host;
  var $port;
  
  // Constructor
  function vlc($hostIn, $portIn)
  {
    $this->host = $hostIn;
    $this->port = $portIn;
  }
  
  function play()
  {
    $this->pause(); // the pause command toggles in vlc
  }
  
  function pause()
  {
    $this->tellVLC("pause");
  }
  
  // Skips forwards by 5mins (300sec)
  function next()
  {
    $this->jumpForwards(300);
  }
  
  // Skips backwards by 5mins (300sec)
  function previous()
  {
    $this->jumpBackwards(300);
  }
  
  // Skips to the current time + delta
  function jumpForwards($delta)
  {
    $this->skipTo($this->currentTime() + $delta);
  }
  
  // Skips to the current time - delta
  function jumpBackwards()
  { 
    $this->skipTo($this->currentTime() - $delta);
  }
  
  // Jumps straight to $time in seconds
  function skipTo($time)
  {
    $this->tellVLC("seek $time");
  }
  
  // This only works sometimes. Which causes skip to fail.
  function currentTime()
  {
    return shell_exec("echo get_time | nc.openbsd -w 1 localhost 1234 | grep -n 3 | sed -e 's/3:> //g'");
  }
  
  function tellVLC($control)
  {
    return shell_exec("echo $control | nc.openbsd -w 1 $this->host $this->port");
  }
  
  function currentTrack()
  {
    return shell_exec("echo status | nc.openbsd -w 1 localhost 1234 | grep input | sed -e 's/> //g' -e 's/( //g' -e 's/new//g' -e 's/ ://g' -e 's/input: //g' -e 's/)//g'");
  }
  
  function currentState()
  {
    return shell_exec("echo status | nc.openbsd -w 1 localhost 1234 | grep state | sed -e 's/( //g' -e 's/state //g' -e 's/ )//g'");
  }
}// end vlc class

?>

I'm not going to fix the broken parts (skipping and such) because I'd be fixing an already undesirable solution (the -w flag). If anyone can help me on that front it'd be great!

Last edited by BaconPie (2010-11-13 18:14:59)

Offline

Board footer

Powered by FluxBB