Is it possible to play local mp3s through the Player class in Hallon?

1 view
Skip to first unread message

Paul Sturgess

unread,
Apr 25, 2012, 5:44:18 PM4/25/12
to ruby-...@googlegroups.com
I was just wondering what support Hallon has for playing local mp3s?

In the Track class I can see ::local and local? methods, however, I can't really see how those might be used.

Kim Burgestrand

unread,
Apr 25, 2012, 6:00:15 PM4/25/12
to Hallon on behalf of Paul Sturgess
Thanks for re-posting it here Paul. :)

Hallon itself has no support for local mp3s — the support for that in the Spotify client
actually comes from their own programming outside of libspotify. With that said, nothing
is really hindering you from actually taking a local track and streaming it through the
Hallon::OpenAL client… but it’s not really built for that so it won’t be very comfortable.

With that said, local tracks in libspotify are kind of cool. Like you’ve noticed, you can
create a local track using Track.local(title, artist, album, length). What this does is give
you an actual Track where Track#local? will return true.

(by the way, the spotify URIs for these tracks are spotify:local:artistname:albumname:trackname:length,
 so for example: spotify:local:Ziggy+Marley::Beach+In+Hawaii:)

Now, the idea with local tracks is that Spotify will try to match the given information with
their entire database of tracks. If they do, you’ll be able to receive more information about
the track, browse it’s artists and even play it like it was any other track! So, in a way it’s
kind of like a search.

Unfortunately I’ve been unable to get it working now on libspotify v11, I’m not sure if it’s
a bug in libspotify or if I’m simply not waiting long enough. The track is properly created,
and you can create a link to it (like the one above), but browsing it’s information just returns
empty results.

Regards,
— Kim

On Wednesday, 25 April 2012 at 23:44, Hallon on behalf of Paul Sturgess wrote:

I was just wondering what support Hallon has for playing local mp3s?

In the Track class I can see ::local and local? methods, however, I can't really see how those might be used.

-- You received this message because you are subscribed to the Hallon ruby gem mailing list.
 
- To view this group online, visit https://groups.google.com/d/forum/ruby-hallon
- To post to this group, send email to ruby-...@googlegroups.com.
- To unsubscribe from this group, send email to ruby-hallon...@googlegroups.com.

Kim Burgestrand

unread,
Apr 25, 2012, 6:03:03 PM4/25/12
to ruby-...@googlegroups.com
Oh, also, I’ve updated the documentation for Track.local — it should be more clear now: http://rdoc.info/github/Burgestrand/Hallon/master/Hallon/Track.local

Paul Sturgess

unread,
Apr 25, 2012, 6:43:31 PM4/25/12
to ruby-...@googlegroups.com
Thanks for the reply Kim.

That's interesting that libspotify does not handle the playing of local mp3s. In an ideal world, I was hoping that there would be a way of setting a local directory path that the search would be able to use for matching against. I need to read up some more on libspotify.

Essentially the way the local mp3s integrate seamlessly into the Spotify Desktop app is something i'd love to imitate in a ruby based player using Hallon.

Kim Burgestrand

unread,
Apr 26, 2012, 5:52:43 PM4/26/12
to Hallon on behalf of Paul Sturgess
On Thursday, 26 April 2012 at 00:43, Hallon on behalf of Paul Sturgess wrote:
That's interesting that libspotify does not handle the playing of local mp3s. In an ideal world, I was hoping that there would be a way of setting a local directory path that the search would be able to use for matching against. I need to read up some more on libspotify.
About the local track matching. I’ve had other people reproduce the bug where local tracks are never available. However, if you add the local track to a playlist and process some events it will become available (assuming libspotify can match the track), and you’ll be able to play it!

Given that local tracks are loaded (they return true for #loaded?), it means #load is pretty useless for them. What you can do is add the local track to a playlist, and then wait for the track to become available instead. It’s still entirely possible that the track is successfully looked up, but not available (#available?) for playback, though.
 
Essentially the way the local mp3s integrate seamlessly into the Spotify Desktop app is something i'd love to imitate in a ruby based player using Hallon.
I’m sorry to say it’s really beyond the scope of Hallon itself. Hallon just aims to support libspotify in the best possible way in Ruby, nothing more.

However, I’ve done my best to abstract away the streaming of audio in Hallon. Given that you have a way to play streaming audio in Ruby, it’s possible to write an audio driver for Hallon and use it to play the streaming music. I’ve documented on how these drivers are written in the documentation for ExampleAudioDriver (http://rdoc.info/github/Burgestrand/Hallon/master/Hallon/ExampleAudioDriver). So, assuming you could find a gem that supports both audio streaming and local mp3 playback, a driver could be written to use it with Hallon! It’s kind of an advanced topic, but very doable. If this imaginary audio gem for Ruby would also support local files, you’d have all you need for playing both local files and streaming audio.

Unfortunately I haven’t found any gems with acceptable support for streaming. This is why I wrote hallon-openal (http://github.com/Burgestrand/hallon-openal), but my aim with that gem is to do the minimal amount of work to be able to stream audio with Hallon and nothing more. Writing and maintaining a generic audio gem for Ruby supporting both local files and streaming would be far too much work combined with everything else I want to be doing.

PS: there is a gem around coreaudio for ruby (https://github.com/nagachika/ruby-coreaudio) that has streaming support. Earlier, Hallon had an audio driver that used this gem, but I had to pull it since the coreaudio gem did not keep an internal buffer of audio to be played between giving it audio data. This meant that if you had the *slightest* CPU hickup (or even when just idling) you would hear a lot of audio tearing, which is not really acceptable.

Regards,
— Kim
Reply all
Reply to author
Forward
0 new messages