--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/7Tm7LD62lqk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/726f5b97-c459-4ffd-b199-e96ade574051n%40googlegroups.com.
I’m surprised threads did not work.
Have your tired using soundloader in a thread, and starting the thread far enough in advance to ensure the file has been loaded before play is called?
--
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/bef7257f-af70-4aad-8017-ef05d035ea2en%40googlegroups.com.
from kivy.core.audio import SoundLoader
def sound_loader(self, *args):
self.thread_sound = Thread(target=self.sound_load_now)
self.thread_sound.daemon = True
self.thread_sound.start()
def sound_load_now(self, *args):
sound = SoundLoader.load('mytest.ogg')
trigger1 = Clock.create_trigger(self.sound_loader, timeout=0, interval=False, release_ref=True)
trigger1()
sound.play()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/63effdb3.170a0220.9504a.a63cSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
I’ll assume that it takes some non-trivial amount of time to load the sound.
The sound must have completed loading prior to being played.
As written, you are kicking off a separate thread to load the file, then waiting for it to complete.
You could try loading and playing the sound in a separate thread, or find a way to load the sound far enough in advance of playing the sound that it is loaded prior to being played.
Looking specifically at your code, you scheduling the loader, then calling play on the sound. I’m surprised this does not cause an error.
Is there something unusual about your sound file? On a laptop, I have never experienced a long delay in loading a file.
You might want to try something like this:
from kivy.app import App
from kivy.lang import Builder
from kivy.core.audio import SoundLoader
from kivy.clock import Clock
kv = """
BoxLayout:
Label:
text: 'Audio Load test'
AnchorLayout:
Button:
size_hint: None, None
size: 100, 48
text: 'Play'
on_release: app.play()
"""
class SoundApp(App):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.sound = None
def build(self):
return Builder.load_string(kv)
def play(self):
self.sound = SoundLoader.load('15 - Hide Away.mp3') # your sound file here
Clock.schedule_once(self._play)
def _play(self, _):
self.sound.play()
SoundApp().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAH%3DihGi4fX9aQKCshCENzK_EiMd6v-qVo_q90%2Bs3Hs-orkB3ww%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/63f110e5.170a0220.ae82b.6c27SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Do you have an audio file you can share that illustrates the issue on a laptop?
I’ll try a few solutions.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAH%3DihGjK0mt_RcjOfE%2BRsNEi-fcmZZByc4VHfbxgXThRjvhZWw%40mail.gmail.com.
TextInput:
font_size: 40
text: "Try to write something here right after pressing the play button, you will see that you cannot write for a short time."
halign: 'center'
padding_y: [self.height / 2.0 - (self.line_height / 2.0) * len(self._lines), 0]
"""
class SoundApp(App):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.sound = None
def build(self):
return Builder.load_string(kv)
def play(self):
self.sound = SoundLoader.load('mytest2.mp3') # your sound file here
Clock.schedule_once(self._play)
def _play(self, _):
self.sound.play()
SoundApp().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/63f11ca4.4a0a0220.a1782.17a1SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
I added some timing info. That file is loading on my desktop in 0.11 seconds. I do not see the delay.
Here I have added timing info, and one version threaded, one version running on the main thread.
From a cold start:
Play Load Time: 0.117 seconds
start to play time: 0.118 seconds
Thread start from a cold start:
Thread Play - Load Time: 0.116 seconds
Thread Play - start to play time: 0.117 seconds
Let me know what you see.
import threading
from time import perf_counter
from kivy.app import App
from kivy.core.audio import SoundLoader
from kivy.lang import Builder
kv = """
<PlayButton@Button>:
size_hint: None, None
size: 100, 48
BoxLayout:
Label:
text: 'Audio Load test'
AnchorLayout:
BoxLayout:
size_hint: None, None
size: self.minimum_size
PlayButton:
text: 'Play'
on_release: app.play()
PlayButton:
text: 'Thread Play'
on_release: app.thread_play()
TextInput:
font_size: 40
text: "Try to write something here right after pressing the play button, you will see that you cannot write for a short time."
halign: 'center'
padding_y: [self.height / 2.0 - (self.line_height / 2.0) * len(self._lines), 0]
"""
class SoundApp(App):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.sound = None
def build(self):
return
Builder.load_string(kv)
def thread_play(self):
t = threading.Thread(target=self._play)
t.start()
def _play(self, *args):
start = perf_counter()
self.sound = SoundLoader.load('mytest2.mp3') # your sound file here
print(f'Thread Play - Load Time: {perf_counter() - start: 0.3f} seconds')
self.sound.play()
print(f'Thread Play - start to play time: {perf_counter() - start: 0.3f} seconds')
def play(self):
start = perf_counter()
self.sound = SoundLoader.load('mytest2.mp3') # your sound file here
print(f'Play Load Time: {perf_counter() - start: 0.3f} seconds')
self.sound.play()
print(f'start to play time: {perf_counter() - start: 0.3f} seconds')
SoundApp().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAH%3DihGgNuzzRhwTnDv9toAh-xf_QehMoQGV-m0x%2BxFNNxVaTQg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/63f13610.c50a0220.7c515.166fSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
When you used the threaded version, can you type in the TextInput?
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAH%3DihGj9RMgwt7rLNSS_CO5QHk1Wp7zk_Xw8x%2BoSZa%3D6dP3gOQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/63f141fc.170a0220.86fb6.7c4fSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Hmmm. Strange. I’m heading out to so some errands – but I’ll create a long audio file and see if I can create a reproducer.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAH%3DihGiYeEf3biKvnoeSWbb6_qLJkbgd_kvG6-y65JhBDGQWdA%40mail.gmail.com.
I opened your audio file in audacity, created multiple copies and exported as an mp3 file. The resulting file is 98,486 KB, and has a playtime of over an hour. It still works fine for me. Load time is 0.11 seconds.
I’m running Windows11, using Gstreamer.
Could you have a system configuration issue?
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/63f14665.370a0220.d1515.8e17SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/63f16fb5.620a0220.57cb1.6cccSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
I don’t have any android platforms. I can do a run on an intel mac.
What audio provider are you using? Do you see the problem on Mac, or only on Android?
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAH%3DihGiWrtkpf5uddOLntpUoYRE2rbDjudOF4%2BQ9bvoSe8T4cQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/63f21e12.630a0220.a3749.55a1SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAH%3DihGiPdF9qcdX%2BG9yf7F8YBNja9Kb8W1H%2Bx%3DGo%3D5NAznRQtA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/F56A965F-EEDC-43E9-97BB-9151B1AD21D6%40cox.net.
Everytime i start Kivy with KIVY_AUDIO=ffpyplayer, it shows:
objc[44991]: Class SDLApplication is implemented in both /Test/venv/lib/python3.9/site-packages/kivy/.dylibs/SDL2 (0x1082082b0) and /Test/venv/lib/python3.9/site-packages/ffpyplayer/.dylibs/libSDL2-2.0.0.dylib (0x1111ea558). One of the two will be used. Which one is undefined.
objc[44991]: Class SDLAppDelegate is implemented in both /Test/venv/lib/python3.9/site-packages/kivy/.dylibs/SDL2 (0x108208300) and /Test/venv/lib/python3.9/site-packages/ffpyplayer/.dylibs/libSDL2-2.0.0.dylib (0x1111ea5a8). One of the two will be used. Which one is undefined.
objc[44991]: Class SDLTranslatorResponder is implemented in both /Test/venv/lib/python3.9/site-packages/kivy/.dylibs/SDL2 (0x108208418) and /Test/venv/lib/python3.9/site-packages/ffpyplayer/.dylibs/libSDL2-2.0.0.dylib (0x1111ea620). One of the two will be used. Which one is undefined.
objc[44991]: Class SDLMessageBoxPresenter is implemented in both /Test/venv/lib/python3.9/site-packages/kivy/.dylibs/SDL2 (0x108208440) and /Test/venv/lib/python3.9/site-packages/ffpyplayer/.dylibs/libSDL2-2.0.0.dylib (0x1111ea648). One of the two will be used. Which one is undefined.
objc[44991]: Class SDL_cocoametalview is implemented in both /Test/venv/lib/python3.9/site-packages/kivy/.dylibs/SDL2 (0x1082083a0) and /Test/venv/lib/python3.9/site-packages/ffpyplayer/.dylibs/libSDL2-2.0.0.dylib (0x1111ea698). One of the two will be used. Which one is undefined.
objc[44991]: Class SDLOpenGLContext is implemented in both /Test/venv/lib/python3.9/site-packages/kivy/.dylibs/SDL2 (0x108208350) and /Test/venv/lib/python3.9/site-packages/ffpyplayer/.dylibs/libSDL2-2.0.0.dylib (0x1111ea6e8). One of the two will be used. Which one is undefined.
objc[44991]: Class SDLWindow is implemented in both /Test/venv/lib/python3.9/site-packages/kivy/.dylibs/SDL2 (0x108208490) and /Test/venv/lib/python3.9/site-packages/ffpyplayer/.dylibs/libSDL2-2.0.0.dylib (0x1111ea878). One of the two will be used. Which one is undefined.
objc[44991]: Class Cocoa_WindowListener is implemented in both /Test/venv/lib/python3.9/site-packages/kivy/.dylibs/SDL2 (0x1082084b8) and /Test/venv/lib/python3.9/site-packages/ffpyplayer/.dylibs/libSDL2-2.0.0.dylib (0x1111ea8a0). One of the two will be used. Which one is undefined.
objc[44991]: Class SDLView is implemented in both /Test/venv/lib/python3.9/site-packages/kivy/.dylibs/SDL2 (0x108208530) and /Test/venv/lib/python3.9/site-packages/ffpyplayer/.dylibs/libSDL2-2.0.0.dylib (0x1111ea918). One of the two will be used. Which one is undefined.
objc[44991]: Class METAL_RenderData is implemented in both /Test/venv/lib/python3.9/site-packages/kivy/.dylibs/SDL2 (0x108208210) and /Test/venv/lib/python3.9/site-packages/ffpyplayer/.dylibs/libSDL2-2.0.0.dylib (0x1111ea990). One of the two will be used. Which one is undefined.
objc[44991]: Class METAL_TextureData is implemented in both /Test/venv/lib/python3.9/site-packages/kivy/.dylibs/SDL2 (0x108208260) and /Test/venv/lib/python3.9/site-packages/ffpyplayer/.dylibs/libSDL2-2.0.0.dylib (0x1111ea9e0). One of the two will be used. Which one is undefined.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/0cff2c0d-735d-484d-b069-ed40a8b491ban%40googlegroups.com.
Looks like it is viewed as a non-issue: https://github.com/matham/ffpyplayer/issues/68
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/08a14308-f405-46c1-b7a0-76ee515293b4n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/08a14308-f405-46c1-b7a0-76ee515293b4n%40googlegroups.com.
I can’t speak to any issues on Android, but looking at the source code for Soundloader, it selects the native android media player on android.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/1f81c2dc-263f-4f09-80ab-3cb7a620b882n%40googlegroups.com.