Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application Hangs When Using play_sound in Kivy 2.3.1 (Works in 2.3.0) #726

Open
philia897 opened this issue Dec 30, 2024 · 1 comment
Open

Comments

@philia897
Copy link

Description:

In Kivy 2.3.1, the application hangs unexpectedly when attempting to play one stone by the user. After debugging for a while, this bug seems to be caused by the "play_sound" function under gui/sound.py.

There is no error or warning message, and the application becomes unresponsive.

This issue does not occur in Kivy 2.3.0, where the same code runs without issues. The problem seems to be a regression introduced in Kivy 2.3.1.

Steps to Reproduce:

  1. Install Kivy 2.3.1: pip install kivy==2.3.1
  2. Run the application, click once on the board and observe that the application hangs.
  3. Roll back to Kivy 2.3.0: pip install kivy==2.3.0
  4. Run the same code, and notice that the application works fine.

You can replace the function content of play_sound with pass to see the difference.

Expected Behavior:

The application should play the sound and remain responsive, as it does in Kivy 2.3.0.

Actual Behavior:

The application hangs without any error or warning, even using katrain -d.

Environment:

Kivy Version: 2.3.1
Python Version: Python 3.11 (I tested Python 3.12 and 3.13 as well, this issue seems have nothing to do with the Python version)
Operating System: Arch Linux x86_64 with KDE Plasma

The OS did matter, as when I manually set ranking to be: [("ffplay", 100), ("sdl", 0), ("gst", 0), ("", 0)], there are errors about FFmpeg but does not hang, when the SoundLoader uses gst, it hangs. My system installed gstreamer 1.24.10-2 and ffmpeg 2:7.1-5

I believe it shall be one bug of Kivy, but I did not dive much about that.

Suggestion:

The easiest way to fix this issue is to limit the kivy version to be under 2.3.1 in the pyproject.toml.

Or use pygame instead, I tried this approach as well and it seems to be much more stable than Kivy.

Here is the code snippet I tried:

import pygame
import os

base_dir = os.path.dirname(os.path.realpath(__file__))

def play_sound(file, volume=1, cache=True):
    try:
        sound_file = os.path.join(base_dir, "..", "sounds", file)

        pygame.mixer.init()
        sound = pygame.mixer.Sound(sound_file)
        sound.set_volume(volume)
        sound.play()
    except Exception as e:
        print(f"Error playing sound with Pygame: {e}")

and it works fine.

@papillon
Copy link

papillon commented Jan 1, 2025

I can confirm the issue and the resolution. Kivy-2.3.1 freezes the application after the first stone, kivy-2.3.0 works fine.

Operating System: Linux Mint 22 Cinnamon edition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants