Custom Audio player

66 views
Skip to first unread message

Charles longwe

unread,
Mar 10, 2023, 4:41:52 PM3/10/23
to Kivy users support
i can play,pause and resume an audio. But if i want to play another song the songs play concurrency. Please help me how can I use unload() in SounderLoader whenever playing another song.

Elliot Garbus

unread,
Mar 10, 2023, 6:35:07 PM3/10/23
to kivy-...@googlegroups.com

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.

 

Charles longwe

unread,
Mar 13, 2023, 1:30:35 AM3/13/23
to Kivy users support
of  course mind about pause or play.....Just press on  mdchip chip it will work but when i press another song on list ...two songs play.
i want you to help me that if i press the another song on the list,the first song must be stoped and play the pressed one.....please the audio files
Bondarecord.py

Charles longwe

unread,
Mar 13, 2023, 1:36:00 AM3/13/23
to kivy-...@googlegroups.com
i mean for playing the audio press on mdchip and change audio files

Elliot Garbus

unread,
Mar 13, 2023, 10:07:31 AM3/13/23
to kivy-...@googlegroups.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()
Reply all
Reply to author
Forward
0 new messages