Hi all,

I am trying to create a listbox using canvas. My requirement is when i scroll through the menu items (which are just images) it should play audio files of about 20 secs. But I am not able to interrupt the audio when I am scrolling down quickly. Here is the code I wrote:

import appuifw, graphics, e32
import audio
import key_codes

count = 0
y = 0
sound = 0

def quit():
app_lock.signal()

appuifw.app.exit_key_handler=quit
appuifw.app.screen='full'
snd_lock = e32.Ao_lock()

def handle_redraw(rect):
global y
c.clear(0xffffff)
c.blit(image)
c.blit(image1,target=(0,40))
c.blit(image2,target=(0,80))
c.blit(bg,target=(0,y)) #acts as navigation bar

bg=graphics.Image.open("bg.jpg")
image=graphics.Image.open("image.jpg")
imagehlp=graphics.Image.open("image1.JPG")
imagewf=graphics.Image.open("image2.jpg")

c = appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
appuifw.app.body=c

def sound_callback(prev_state, current_state, err):
if current_state == audio.EOpen:
snd_lock.signal()

def play():
global sound
while sound.state() == 1: #plays the sound file only if file is open
e32.ao_yield()
sound.play(callback = sound_callback)
break


def playMP3():
global sound
sound = audio.Sound.open("aud.mp3")
play()

def press_down():
global count
global y
global sound
if sound != 0 and sound.state() == 2: #checks if an audio is playing
snd_lock.signal()
y+=40
count+=1
handle_redraw(())
if count == 1:
playMP3()
snd_lock.wait()
sound.close()
elif count == 2:
playMP3()
snd_lock.wait()
sound.close()

c.bind(key_codes.EKeyDownArrow, press_down)

app_lock=e32.Ao_lock()
app_lock.wait()

As far as I am considered this should work fine. But when I press down when the first audio is playing it will scroll down but the next audio is not playing and after scrolling down to 2 menu items application will close off.

Can somebody help me???
Hope to get a reply as soon as possible.

Regards
Simil