I don’t think you need to use unload(). Do you have 1 sound object or are you creating multiple sound objects?
Share a minimal runnable example
--
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/8280d403-2afe-4acb-8107-4948ae672f6bn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/67b62576-a50d-4e0c-8bb6-694f0bc64710n%40googlegroups.com.
I suspect you were playing sounds, and never stopping them. I changed the play button to a ToggleButton, and use the state of the button to stop or play songs.
Also, change the source to a StringProperty, as below.
from kivy.core.audio import SoundLoader
from kivy.lang import Builder
from kivy.properties import NumericProperty, StringProperty
from kivymd.app import MDApp
from kivymd.uix.behaviors.toggle_behavior import MDToggleButton
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.button import MDRoundFlatIconButton
from kivymd.uix.card import MDCard
kv = """
BondaBoard:
orientation:'vertical'
MDTopAppBar:
title:'Bonda Recording'
MDScrollView:
MDList:
id: song_list
spacing:'8dp'
padding:'8dp'
BondaRecord:
source:'music/01-01- Bohemian Rhapsody.mp3'
BondaRecord:
source:'music/02 - Sweet Little Angel (Live At The Regal Theater, Chicago, 1964).mp3'
BondaRecord:
source:'music/15 - Hide Away.mp3'
<PlayButton>: # create a toggle button
icon:'play'
text: 'Play'
icon_size:dp(32)
pos_hint:{'right':.8}
group: 'play'
<BondaRecord>
size_hint_y:None
height:dp(56)
elevation:3
MDBoxLayout:
MDChip:
id:chip
text: root.source
pos_hint:{'left':.8,'top':1}
on_release: root.play_record()
PlayButton:
on_state: root.play_stop(self.state)
MDIconButton:
icon:'download'
icon_size:dp(32)
pos_hint:{'right':1}
"""
class PlayButton(MDRoundFlatIconButton, MDToggleButton):
pass
class BondaRecord(MDCard):
source = StringProperty()
sound_pos = NumericProperty()
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.sound = None
def play_record(self):
print(self.ids.chip.text)
def play_stop(self, state):
if state == 'normal':
self.sound.stop()
else:
self.sound = SoundLoader.load(self.source)
self.sound.play()
class BondaBoard(MDBoxLayout):
pass
class Player(MDApp):
def build(self):
return Builder.load_string(kv)
if __name__ == "__main__":
Player().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAMsm4MnmRkBEb_Oy%3DenzPypLbr%2B2QF_%2BidZYddAPbeF3N34kvg%40mail.gmail.com.