Play any file on any MPD

Play any file on any MPD

Play any file on any MPD

One of the things, I always wanted to be able to do, was playing files from outside of MPD music_directory. Normally, when you want to play such a file, MPD will return Not found error – it means, that file was not found in MPD database. In other words MPD only plays files which are in its music_directory and are indexed (are in MPD database).

First approach to achieve my goal was adding Play to… function in O!MPD v1.02. This let to play any file from O!MPD database on any MPD in the network (even if this file was not indexed by MPD, i.e. it could be outside of MPD music_directory). O!MPD v1.03 extends this feature – it lets to play any track that www server has access to: both outside of O!MPD and MPD media directories. All you need is properly installed MPD – no need to worry about updating or even configuring its database.

How it works

Just add your MPD to O!MPD Player profile and select it as active player. Next choose any album or track from O!MPD library and play it. That’s it! Rest is done in the background: O!MPD sends command to play these tracks to MPD. When chosen tracks are in MPD database, they are played in normal way – as files. But when the tracks are not found in MPD DB, MPD sends Not found error to O!MPD. Then O!MPD prepares http streams, sends them back to MPD and MPD plays them just like streams from Internet. In Now playing everything looks and works as usual – you can see all information about track, jump to album, look for lyrics, seek track, etc. The only difference that lets you distinguish whether MPD is playing file or stream is text (stream) added next to file type:

O!MPD playing file outside of MPD database

What’s more, in v1.03 you can even play files outside of O!MPD library, i.e. files outside of directory defined in $cfg['media_dir'] and not indexed by O!MPD. For this purpose File browser was added. It is available from Library -> File or from album view (Browse…). By default file browser has access only to directory defined in $cfg['media_dir']. If you want it to have access to files outside of this dir, you need:

  • change $cfg['allow_access_to_all_files'] to true
  • give access to this files to your web server (if not granted already)

In file browser you can navigate to any directory (e.g. just plugged-in usb drive) and play files or whole directories:

Actions available in folder submenu

Actions available in file submenu

Since files outside of $cfg['media_dir'] are not indexed by O!MPD, informations displayed in Now Playing come directly from MPD. Depending on MPD version you use, these informations can be more or less limited – not all tags can be available. Anyway, O!MPD will try to read as much tags from MPD as possible, so Now Playing can look like this:

O!MPD playing files outside of media dirrectory.

Clicking artist name, genre, year will bring you to search results for this items, while clicking album title will open file browser with directory containing this file.

Final thoughts

This feature is very useful for MPDs not powered up all the time: in my case it’s for example MPD in my bedroom. I don’t turn it on everyday – just from time to time. Before I had developed this feature, when I wanted to listen to new albums in my bedroom, I had to update this MPD – it was so inconvenient. Now this player is always ready to play any album, right after turning on.

I also use it to play music on my smartphone – I just installed MPD on it, didn’t have to worry about giving access to music directory on NAS.

And, of course, I use it to quick play files from external sources (like usb drives) – that was main goal.

I hope you find it useful, too.

2 thoughts on “Play any file on any MPD

  1. kos

    Hi Artur!
    I really appreciate your hard work! You have done a very nice job!
    One quick question: i am using ompd on a https website and i think this in why streaming doesnt work. Is there a way to make it work (streaming over https)?
    Thank you very much!!!

    1. Artur Sierżant Post author

      Hi,
      thank you for comment – nice to hear you like O!MPD.
      Yes, there is a problem with https streaming. I don’t know why it doesn’t work – I checked this on my system (MDP 0.19.21 with support for https protocol) and can’t tell what to do to make it works. I’ll try to investigate problem more deeply, but can’t promise anything…

      Best regards,
      Artur

Leave a Reply

Your email address will not be published. Required fields are marked *