Kivy Audio: ffpyplayer error does not throw exception

148 views
Skip to first unread message

JC

unread,
Jan 24, 2024, 4:39:01 PM1/24/24
to Kivy users support
Hi,

I am testing a simple implementation of Kivy Audio and came across the following:

When ffpyplayer has an error (see debug log snippet below) it does not get caught by try/except and ends up crashing Kivy (I am testing using the kivy launcher).

As it doesn't throw an exception, I can't test for it and handle it in the code. See log extract below and code snippet.

Is this a bug? 
Is there a more robust/reliable way to implement an audio player where source is an URL? (Playing sound from URL seems to have other issues for me: "pause/play" works fine for me from a file but if the source is URL it acts up e.g. it resumes play and then restarts again from the start)

From kivy debug log:

[WARNING] [ffpyplayer  ] [https @ 0000020bebfeb9c0] HTTP error 403 Forbidden
[ERROR  ] [ffpyplayer  ] https://www.buzzsprout.com/1984146/14368896-january-24-2024.mp3: Server returned 403 Forbidden (access denied)

Code snippet:
sound = SoundLoader.load("https://www.buzzsprout.com/1984146/14368896-january-24-2024.mp3")
if sound:
    try:
        sound.play()
    except Exception as e:
        print(e)



elli...@cox.net

unread,
Jan 24, 2024, 5:19:53 PM1/24/24
to kivy-...@googlegroups.com
I would recommend using UrlRequest to download the audio file https://kivy.org/doc/stable/api-kivy.network.urlrequest.html#module-kivy.network.urlrequest, use the SoundLoader to play it. 


From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> on behalf of JC <kiv...@gmail.com>
Sent: Wednesday, January 24, 2024 1:39 PM
To: Kivy users support <kivy-...@googlegroups.com>
Subject: [kivy-users] Kivy Audio: ffpyplayer error does not throw exception
 
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/04cfcc3d-11dd-4430-918d-3223f71771f8n%40googlegroups.com.

JC

unread,
Jan 25, 2024, 9:03:12 AM1/25/24
to Kivy users support
Thanks. Downloading it first would add quite a bit of delay for my intended use-case (the "button" that triggers the code is a "Play" button so the user will expect something in good time). As these are links to podcast audio files they can be comparatively big. I actually provide a separate download option too.

I didn't find much re. 403 error with ffpyplayer but there's quite a few hits on this for ffmpeg, which I imagine are caused by similar things? The link that causes the problem for me does a redirect and the actual mp3 filename is quite different from what it is in the original URL. I guess Buzzsprout does this to counter scraping?

Had a look at the Kivy source code and there's no handling for the situation where ffpyplayer throws an error (see line 119, kivy/kivy/core/audio/audio_ffpyplayer.py at master · kivy/kivy · GitHub). 

Here's what you get when using that snippet of code for ffpyplayer directly in python terminal:

>>> from ffpyplayer.player import MediaPlayer
>>> ffplayer = MediaPlayer("https://www.buzzsprout.com/1984146/14368896-january-24-2024.mp3")                        
>>> [https @ 000002168f74fd40] HTTP error 403 Forbidden

https://www.buzzsprout.com/1984146/14368896-january-24-2024.mp3: Server returned 403 Forbidden (access denied)

elli...@cox.net

unread,
Jan 25, 2024, 9:50:42 AM1/25/24
to Kivy users support
It appears that the SoundLoader was not architected with a URL in mind.  This looks like a bug (or a worthy feature request) to me.  I suggest reporting it on the kivy github.

You could try using the ffpyplayer directly, here are the docs: https://matham.github.io/ffpyplayer/player.html#ffpyplayer.player.MediaPlayer
Or make the changes to the source and issue a PR.

As a quick fix you could look at checking the file is reachable on the network prior to using the SoundLoader. 

Sent: Thursday, January 25, 2024 6:03 AM

To: Kivy users support <kivy-...@googlegroups.com>
Subject: Re: [kivy-users] Kivy Audio: ffpyplayer error does not throw exception
 

JC

unread,
Jan 25, 2024, 1:28:27 PM1/25/24
to Kivy users support
Thanks for the help -- agreed. Reported on github. (My first!)

JC

unread,
Jan 26, 2024, 9:10:08 AM1/26/24
to Kivy users support
Just in case anyone with similar problem might find it useful:

The issue with pause/play causing the audio to resume and then start again from scratch can be worked around by calling the seek() via Clock.schedule_once() after you call play(). The reason is that in the Kivy code the play() method for ffpyplayer in audio_ffpyplayer.py ends with a dispatch event followed by a seek(0). I think timing issues are causing this seek(0) to be called *after* you do seek(position) in your own code.

Reply all
Reply to author
Forward
0 new messages