Mohammadhzp
Mohammadhzp

Reputation: 558

Audio(mp3) steaming in android and IOS using kivy

I have installed kivy version 1.8.1 for python 2.7 on fedora 20

Since I am new to kivy I wanted to know if I can use kivy for audio streaming in android and IOS

I tried an example,but it's not even playing on my desktop

from kivy.app import App
from kivy.core.audio import SoundLoader

class TestApp(App):
    def build(self):
        sound = SoundLoader.load('http://194.106.198.57:8090/club_low.mp3')
        if sound:
            print("Sound found at %s" % sound.source)
        print("Sound is %.3f seconds" % sound.length)
        sound.play()
TestApp().run()

the output of above code:

[INFO              ] Kivy v1.8.0
[INFO              ] [Logger      ] Record log in /home/mohammad/.kivy/logs/kivy_14-09-11_13.txt
[INFO              ] [Factory     ] 157 symbols loaded
[DEBUG             ] [Cache       ] register <kv.lang> with limit=None, timeout=Nones
[DEBUG             ] [Cache       ] register <kv.image> with limit=None, timeout=60s
[DEBUG             ] [Cache       ] register <kv.atlas> with limit=None, timeout=Nones
[INFO              ] [Image       ] Providers: img_tex, img_dds, img_pygame, img_gif (img_pil ignored)
[DEBUG             ] [Cache       ] register <kv.texture> with limit=1000, timeout=60s
[DEBUG             ] [Cache       ] register <kv.shader> with limit=1000, timeout=3600s
[DEBUG             ] [Audio       ] register SoundPygame
[INFO              ] [Audio       ] Providers: audio_pygame (audio_pygst, audio_sdl ignored)
[DEBUG             ] [App         ] Loading kv </home/work/python/pama_radio/andriod_app/test.kv>
[DEBUG             ] [App         ] kv </home/work/python/pama_radio/andriod_app/test.kv> not found
[WARNING           ] [Audio       ] Unable to find a loader for <http://194.106.198.57:8090/club_low.mp3>
 Traceback (most recent call last):
   File "/home/work/python/pama_radio/andriod_app/main.py", line 11, in <module>
     TestApp().run()
   File "/usr/lib/python2.7/site-packages/kivy/app.py", line 766, in run
     root = self.build()
   File "/home/work/python/pama_radio/andriod_app/main.py", line 9, in build
     print("Sound is %.3f seconds" % sound.length)
 AttributeError: 'NoneType' object has no attribute 'length'

Process finished with exit code 1

I tried video and video player modules,it will work for streaming in DESKTOPS only,it will not work on android (I didn't try IOS) Please let me know if I could use other formats(like aac and ogg)

Upvotes: 2

Views: 2188

Answers (1)

kitti
kitti

Reputation: 14804

This is happening because on desktop you are using gstplayer - the GStreamer-based audio provider - while Android uses pygame as its audio provider. While GStreamer supports streaming audio across the network, pygame does not.

If you look at the output from running your app on the desktop, you should see the following:

[INFO   ] [Audio       ] Providers: audio_gstplayer, audio_pygame (audio_ffpyplayer, audio_sdl ignored)

This means Kivy is using both gstplayer and pygame - if gstplayer cannot handle a given media type, then Kivy will try using pygame. But gstplayer is not available on Android:

[INFO              ] [Audio       ] Providers: audio_pygame (audio_pygst, audio_sdl ignored)

On iOS, the SDL audio provider is used, and I believe that may support streaming, so you might have better luck there. You could also submit an issue on github to request that we add this functionality.

Upvotes: 2

Related Questions