3

I want build a web page that has a button to start omxplayer on my Raspberry Pi. I've been searching but with no results. Does anyone know how to do this? I have Apache and Php installed on my Pi.

1

Firstly may I suggest you rather not use apache, its crazy heavy on resources. You can use nginx with PHP. But also I would recommend not to use PHP either, as its, pretty much a relic.

I would suggest using Python with Flask .

  • Python is really the "main" programming language for Raspberry Pi.
  • Flask is a nice Python/MVC convention (Almost like Razor for C#) that allows you to rapidly develop WebApps and API's (I have tried it and I am a hardcore C# developer, I found the experience very pleasing)

This way you can serve up HTML pages and build back end API's. You will need a bit of JavaScript/jQuery knowledge to do ajax maybe for best user experience, but you can also simply do old school form submits, if you must.

You can then execute shell scripts using Python, that contain the commands, or proxy arguments into the shell script you need for OMXPlayer.

  • I completely agree with using flask, but this doesn't specifically answer 'how do I start omxplayer on the pi via a web interface'. Any chance of a wee example? – goobering Mar 10 '16 at 7:40
  • Well. How do you start omx on the command line ? And then put that into flask ... ;) – Piotr Kula Mar 10 '16 at 7:50
1

One problem you'll run into is making php play the song without timing out. node.js can serve up web pages as well as run omxplayer in a separate thread. It handles multithreading in an unusual way. Everything is multithreaded except your javascript code.

I once programmed a Raspberry Pi to yell Shut Up! as a joke when I accessed it remotely using a browser from another room on port 8000:

// Play a .wav file remotely.
var child_process = require('child_process');

console.log("Program running.");

// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/html"});
  response.end("<!DOCTYPE html>\n<html>\n<head><title>Shut Up</title>    </head>\n<body>Shut Up!<br />Press F5 to hear again.</body></html>\n");

  var child = child_process.spawn("C:\\Source\\SocketIO\\notify.bat");
  child.on('close',function() {
    console.log("Program closed");  
  });
  setTimeout(function() { child.kill(); },5000);
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.