The problem is that if you click on "play button" again, the audio doesn't stop. It restarts.
I wanted to button to be a play/pause button. I tried many things but it would always give me an error message.
Those are the parts of the code that have to do it the audio:
Code: Select all
init python:
renpy.music.register_channel("player", mixer='sfx', loop=False, stop_on_mute=True)
##############
def msg(txt, who=False, sound=False, pic=False, hm=False, p=3, t=2):
if message_time:
h,m = message_time
hm = hm if hm else '%s:%s'%(h,m)
time_update()
hm = get_current_time() if message_time_current else hm
store.m_msg.append((who, txt, sound, pic, hm))
store.yadj.value = store.yadj.range+300
renpy.restart_interaction()
if who:
renpy.play("sfx/new_message.mp3", "sound")
renpy.pause(p)
####################
screen telegram():
frame background "messenger/back.png" xysize (700,975) align (0.9,.5):
frame background None xysize (560, 810) align (0.5,0.58):
viewport id "vp_msg" mousewheel True yadjustment yadj:
vbox spacing 15 xsize 550 xalign 0.4 box_reverse True:
for message in m_msg[::-1]:
$ who, txt, sound, pic, hm = message
$ xgn = 0.0 if who else 1.0
$ xpic = 380
if sound:
hbox spacing -60 xalign xgn:
$ sound = 'sfx/%s.mp3'%(sound)
imagebutton auto "messenger/sound_%s.png" xalign xgn action Play("player", sound)
if hm:
text "{t}%s{/t}"%(hm) style 'txt_time'
elif pic:
hbox spacing -60 xalign xgn:
button xalign xgn xmaximum 580 xpadding 4 top_padding 30 bottom_padding 40 background 'box' hover_background 'h_box':
action Show('full_pic', pic=pic)
add "messenger/pic/%s.jpg"%(pic) size (xpic, xpic/display_aspect_ratio)
if hm:
text "{t}%s{/t}"%(hm) style 'txt_time'
else:
hbox spacing -60 xalign xgn:
button xalign xgn xmaximum 580 xpadding 20 top_padding 10 bottom_padding 30 background 'box':
text "%s"%(txt) style "txt_base"
if hm:
text "{t}%s{/t}"%(hm) style 'txt_time'
Thanks.