Kivy Audio Will Not "Seek," Win 11

149 views
Skip to first unread message

Tim Morton

unread,
Nov 18, 2021, 12:56:45 PM11/18/21
to Kivy users support

According to the documentation Kivy 2.0.0 audio will likely not seek unless played first. However, I cannot get it to seek at all with the attached simple code on Windows 11. It always plays from the beginning and the position is always 0,

Also, I tried to schedule a delay using Clock and the audio does not play at all. What am I missing?

playMp3.py

Elliot Garbus

unread,
Nov 18, 2021, 9:56:42 PM11/18/21
to kivy-...@googlegroups.com

Here is an example.  Change the audiofile and the seek time as you like. 

 

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.core.audio import SoundLoader

kv =
"""
<AudioPlayer>:
    size_hint_y: None
    height: 48
    Button:
        text: 'Play & Seek'
        on_release: root.play()
    Button:
        text: 'Stop'
        on_release: root.stop()

BoxLayout:
    orientation: 'vertical'
    Label:
        text: 'Audio Test'
    AudioPlayer: 
"""


class AudioPlayer(BoxLayout):
   
def __init__(self, **kwargs):
       
self.sound = SoundLoader.load('PinkPanther60.wav')
        
super().__init__(**kwargs)

   
def play(self):
       
self.sound.play()
       
self.sound.seek(55)

   
def stop(self):
       
self.sound.stop()


class AudioTestApp(App):

   
def build(self):
       
return Builder.load_string(kv)


AudioTestApp().run()

--
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/bae3c129-d42e-480c-9266-b0ff902330e9n%40googlegroups.com.

 

Tim Morton

unread,
Nov 19, 2021, 7:22:36 AM11/19/21
to Kivy users support
Elliot, 
Thanks for the reply, but unfortunately, it still will not seek...and late last night I found out why. 

The default Kivy audio provider on Windows is SDL2 and when I looked at the  source (kivy/core/audio/audio_sdl2.pyx) I found it does NOT have a seek method. Only "play" and "stop." In the __init__.py file the "seek" method returns "pass." However, the audio_ffpyplayer.py files DOES have a "seek" method. If one has ffpyplayer installed on his system Kivy will load it and seek will work, but with the default install it will not.

(It would be good if the Docs would reflect this. It would have saved me and others, I'm sure, a lot of "hair pulling.")

I tried ffpyplayer and it works good, but it has a lot of bloat. When packaged with pyinstaller there is around 40MB of added dlls. Since Windows already has the files needed to play audio, this bloat is redundant. While looking for a Python tool to play Windows audio using existing dlls, I found mp3play (https://github.com/michaelgundlach/mp3play). It is old but works flawlessly using only Window's native audio dlls and adds essentially no bloat. I think "playsound" will work as well.

Elliot Garbus

unread,
Nov 19, 2021, 10:29:04 AM11/19/21
to kivy-...@googlegroups.com
This is odd. I’m using the SDL2 provider and it does seek.  It might be the encoding of your audio file. 

Sent from my iPhone

On Nov 19, 2021, at 5:22 AM, Tim Morton <tsmor...@gmail.com> wrote:

Elliot, 

Tim Morton

unread,
Nov 19, 2021, 11:11:00 AM11/19/21
to Kivy users support
Are their different versions of SDL2? Because the code you posted definitely won't seek with any mp3 I have tried.

Here is my info log,

[INFO   ] [Logger      ] Record log in C:\Users\tim\.kivy\logs\kivy_21-11-19_53.txt
[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.3.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.3.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.3.1
[INFO   ] [Kivy        ] v2.0.0
[INFO   ] [Kivy        ] Installed at "C:\Program Files (x86)\Python38-32\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:34:34) [MSC v.1928 32 bit (Intel)]
[INFO   ] [Python      ] Interpreter at "C:\Program Files (x86)\Python38-32\python.exe"
[INFO   ] [Factory     ] 186 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO   ] [Audio       ] Providers: audio_sdl2 (audio_ffpyplayer ignored)
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.6.148201 Compatibility Profile Context 20.50.02.10 27.20.15002.10002'>
[INFO   ] [GL          ] OpenGL vendor <b'ATI Technologies Inc.'>
[INFO   ] [GL          ] OpenGL renderer <b'Radeon(TM) RX 550'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 6
[INFO   ] [GL          ] Shading version <b'4.60'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Base        ] Start application main loop
[INFO   ] [GL          ] NPOT texture support is available

Elliot Garbus

unread,
Nov 19, 2021, 12:51:18 PM11/19/21
to kivy-...@googlegroups.com

Looks like I’m using Gstreamer.

 

[INFO   ] [Logger      ] Record log in C:\Users\ellio\.kivy\logs\kivy_21-11-19_0.txt

[INFO   ] [deps        ] Successfully imported "kivy_deps.gstreamer" 0.3.1

[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.3.0

[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.3.0

[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.3.1

[INFO   ] [Kivy        ] v2.0.0

[INFO   ] [Kivy        ] Installed at "C:\Users\ellio\kivy_venv_200\lib\site-packages\kivy\__init__.py"

[INFO   ] [Python      ] v3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)]

[INFO   ] [Python      ] Interpreter at "C:\Users\ellio\kivy_venv_200\Scripts\python.exe"

[INFO   ] [Factory     ] 186 symbols loaded

[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)

[INFO   ] [AudioGstplayer] Using Gstreamer 1.18.0.0

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

[INFO   ] [Window      ] Provider: sdl2

[INFO   ] [GL          ] Using the "OpenGL" graphics system

[INFO   ] [GL          ] GLEW initialization succeeded

[INFO   ] [GL          ] Backend used <glew>

[INFO   ] [GL          ] OpenGL version <b'4.6.0 NVIDIA 466.79'>

[INFO   ] [GL          ] OpenGL vendor <b'NVIDIA Corporation'>

[INFO   ] [GL          ] OpenGL renderer <b'NVIDIA GeForce RTX 2060/PCIe/SSE2'>

[INFO   ] [GL          ] OpenGL parsed version: 4, 6

[INFO   ] [GL          ] Shading version <b'4.60 NVIDIA'>

[INFO   ] [GL          ] Texture max size <32768>

Tim Morton

unread,
Nov 19, 2021, 1:16:52 PM11/19/21
to Kivy users support
Yes, gstreamer has seek. SDL2 is the only one that dosen't.
Reply all
Reply to author
Forward
0 new messages