Общо показвания

май 07, 2011

How to write yourself a music player in 20 minutes

I am working as JavaScript developer.
I spend most of my work day in the browser (now days 'the browser' being Chrome).
I read my emails.
I read my news.
I talk to my colleagues, friends and family.
I do research.
I code.
I entertain myself.
All in the browser.

However I like to listen to music sometimes. I have a big collection of my favorite music collected over the past 12 years, however to be able to filter it and listen to it I need a separate program, a 'music player'. I asked myself: 'Why should I use an application I cannot modify. Isn't it in the spirit of OpenSource to be able to use something you can read, change and use however you like?'.

I do use open source music player, however it is written in C++ and GTK, language and library I do not understand very well. It does not decode the stream, and I am not really interested in that part. Chrome can decode audio in at least mp3 and ogg formats, so why not use the browser to play back my files. But then again I should be able to display my collection and filter it. How hard could that be to do in the browser.

Not hard at all. Enter OmniGrid. It is able to display your data in a table, sort it and filter it, all it require is that your data is loaded as JSON valid object. My regular music player is Rhythmbox, so I can download the xml file, convert the data with DOM however I like it and load it in the grid view, then filter it. It is very simple and straight forward. I will also need an audio tag and pause button.

So here it is:



OmniGrid requires mootools and mootools-more (of course not the whole of them, you can custom build for it), but it makes the application code very very small! Mine is 117 rows only and most o it is to create the tags and bind events to it because I do not like writing html files, I like creating them with JS on domready.

I encourage you try and write whatever you use on your desktop that is not available yet as web application and share it, so we can finally move on from the desktop paradigm and be able to live online and on whatever laptop/computer we are currently having.

I for example feel pretty awful when my laptop breaks or need to be taken for cleaning, this whole thing can be painless if my digital life was stored on a server and accessible from a web interface, then all i would need would be a browser. Kind of the idea behind 'Chrome OS'. I like it. I agree that maybe not all our data should be on Google's cloud, but I have my own server. I could just store my things on my server. On an encrypted partition. Yeah... and then I could just use any laptop. Any that is not with key loggers on it though...

UPDATE: The code for this small App is available here. It cannot be used as it is, because it assumes you have your rhythmbox DB file in the same directory and assumes the directly structure and your system user name, however it is pretty easy to modify. Enjoy.

Няма коментари: