psychopy.org | Reference | Downloads | Github

Background music is not play

My OS is Win10, PsychoPy version is v2020.1.3

My experiment has four background music (A, B, C, D) and four types of images (a, b, c, d), Each type of image with 10 pictures. Both of the music and image must match in the experiment, such as A must match a. When playing the type ‘a’ image, the background music is ‘A’. However, playing type ‘b’,‘c’ and ‘d’ image, the background music still ‘A’, not change.

The code properties in the first loop :
Begin Experiment

Background_sound sound.Sound('sound/A.wav')

Begin Routine

if Firsttrials.thisN == '0':
      background_sound.play()

End Routine

 if Firsttrials.thisN == '9':
    background_sound.stop()

The code properties in the second loop is :
Begin Experiment

background_sound sound.Sound('sound/B.wav')

Begin Routine

if Firsttrials.thisN == '0':
    background_sound.play()

End Routine

 if Firsttrials.thisN == '9':
    background_sound.stop()

That didn’t work.

I am a student, this is my first time to experiment. I haven’t any idea how to fix it. Please help me.
Sorry for my English, please ask if you found my description a mess.

At the beginning of the experiment, you attempt to assign two different sounds to the same variable name: background_sound. Any variable name can only point to one thing at a time, so the second assignment will over write the first.

You can get around this by using two distinct variable names, e.g.

background_sound_A = sound.Sound(‘sound/A.wav’)
background_sound_B = sound.Sound(‘sound/B.wav’)

and use the appropriate name as required.

But now that I think about it, this would all probably work better if you could change the structure of your experiment to use nested loops instead of consecutive loops, but I guess that depends on whether there is any real difference between your Sgrouphh and Fgrouphl routines.

Lastly, to help make your posts readable please:

1 Like

Got it.
Thanks for your help and reminder.
This is my first time experimenting, I know don’t how to use nested loops instead of consecutive loops.
I have four-part to present. The first part sees the 10 pictures with relative music (A, a). Breaking 30 seconds after, go to the second part (B,b). For instance, (A,a)->30sec–>(B,b)->30sec->(C,c)->30 sec->(D,d). When four-part finished, doing the recall test. I don’t know how to do it better by my limited knowledge. I use the simplest method to finished my experiment.