LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-21-2013, 05:22 AM   #1
mattyshaw
LQ Newbie
 
Registered: Jun 2006
Posts: 4

Rep: Reputation: 0
Simple webpage to control mpd


Hiya

I have the excellent mpd and mpc installed on my system, and want to create a simple webpage to display currently playing song info, with a few links to jump tracks, search, add to playlist, and also to select internet radio streams.

I have done lots of html coding in the past, and a bit of cgi, but not too sure how to achieve this, do I just need to create a link to the mpc binary in my cgi-bin directory, and then in my html code have a link that just reads <a> href="/cgi-bin/mpc next"</a> for example to send the mpc next command to the system ????

I am really keen to get going on this....

Thanks
Matt Shaw
matt@shagshaw.com
 
Old 08-21-2013, 06:43 PM   #2
blip
LQ Newbie
 
Registered: Aug 2013
Posts: 17

Rep: Reputation: Disabled
You can have your browser issue GET or POST requests to the server. Use GET for status checks and gathering information that doesn't change state like querying the current song. If state can change as a result of the HTTP request, such as a request to play the next item, use POST.

GET is easy:
Code:
<a href="mpc.cgi?var=something&var2=else">link</a>
Your CGI script will need to parse the QUERY_STRING environment variable which will contain "var=something&var2=else". Any unusual characters will be URL encoded. So "/" becomes "%2F" (hexadecimal representation) or spaces transform into "+" or "%20". I don't think you need to worry about URL decoding at this point though. It is perfectly legal to request "mpc.cgi?metadata" where QUERY_STRING would simply be "metadata".

In order to POST, you need a form. For example:
Code:
<form action="mpc.cgi" method="POST">
<input type="text" name="textbox" value="sometext">
<input type="submit" value="Go">
</form>
The default enctype is "application/x-www-form-urlencoded" so your script should read standard input and parse it just like QUERY_STRING for GET. In this case, standard input would contain "textbox=sometext". (There is another enctype "multipart/form-data" that is usually used when uploading files but that is harder to parse and not necessary here.)
 
Old 08-22-2013, 06:53 AM   #3
mattyshaw
LQ Newbie
 
Registered: Jun 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Hi

Thanks for your response

at the command line the command mpc next plays the next track, mpc prev plays the previous track, and there are lots of other mpc paramater commands that can be given to control the music

Can the previous poster please explain again in plainer english how in simple html code I can transmit these commands, I totally dont understand the previous entry.....

thanks in advance

Matt
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
“tc” command, making simple traffic control for specific port, lo, and one more thing hudac Linux - Newbie 2 10-24-2012 01:50 AM
Doc for creating a simple webpage satimis Linux - General 14 04-12-2011 05:32 AM
Apache - Changing port for Godaddy's Simple Control Panel strimp099 Linux - Server 1 04-11-2011 01:57 PM
ALSA config options for MPD cant control volume dasy2k1 Linux - Software 0 10-12-2008 06:28 PM
mplayer shows error message [AO_ALSA] Unable to find simple control 'PCM',0 sagsriv Linux - Newbie 4 08-11-2008 08:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration