Reputation: 11875
I tried to make a simple music streaming app using Python+PyObjC following this blog
import Foundation
from AppKit import NSSound
sound = NSSound.alloc()
url = Foundation.NSURL.URLWithString_("http://206.217.213.235:8050/")
sound.initWithContentsOfURL_byReference_(url, True)
sound.play()
And it fails
>>> sound.play()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: cannot access attribute 'play' of NIL 'NSSound' object
Why?
Upvotes: 0
Views: 722
Reputation: 7534
to add to @William Denman's answer initWithContentsOfURL_byReference_
is returning nil, which means an error happened creating the sound. in this case we know its because the URL should point to a valid file that NSSound
understands (AIFF, WAVE, NeXT, SD2, AU, and MP3).
even if NSSound
worked in this instance, it would have to download the entire file before playback; as @William Denman pointed out this doesn't work with streams.
Upvotes: 1
Reputation: 3154
It is because the NSSound object in AppKit provides a way to play AIFF and WAV sound files in Mac applications and not Shoutcast streams. See: http://nodebox.net/code/index.php/PyObjC
I quickly tried to find an existing Python module to do what you want, but it seems none exist. There are however plenty of apps, implemented in Python that do this, that you could analyse to figure out how they do it. For example: https://pypi.python.org/pypi/DeeFuzzer
The best alternative I could find for you was How do I capture an mp3 stream with python that talks about capturing a stream for local playback.
Upvotes: 1