Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Music throughout experiment

Hello,

I want a music file to play throughout an experiment. I'm using it as an auditory distraction throughout the whole experiment. It will currently play but will only go to the next stage of the experiment when the song has finished. Is there any way that I can get the music file to play once completely for the whole experiment?

thanks in advance!

Comments

  • edited February 2021

    Hi @DK21 ,


    Are you running your experiment locally or online?


    It will currently play but will only go to the next stage of the experiment when the song has finished. 

    Indeed, OpenSesame runs the items in sequences in a sequential way. Therefore, what you are trying to do sounds a bit complicated (at least for me) to achieve without coroutines and/or Python inline_script, which are both not supported in OSWeb.


    Cheers,


    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • Hi Lotje,

    I'm running it locally. Thanks for your reply and for that information. This is all new to me and I'm a bit lost 😅

    cheers


    Damien

  • Hi @DK21 ,


    Ok, good to hear that you are not running the study online. ;-)

    Could you upload the script of what you programmed so far (by clicking the paperclip icon)? Then I can give it a thought.


    Cheers,


    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • Hi @DK21 ,


    Sorry, I was totally overthinking this one. It's actually as simple as appending a sampler item to the very beginning of your experiment and settings its duration to 0. (Works both locally and online.)


    Sorry for the confusion! ;-)


    Cheers,


    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • Hi Lotje,

    Thats great, thank you for getting back to me, much appreciated.

  • Hi,

    Related to this discussion, how to play background music (or sound) repeatedly until the end of experiment?

    Sometime we want to play BGM or sound stimuli repeatedly and automatically from first when the BGM ends.


    Thanks

  • Hi @rrr

    Have you tried the above solution? (i.e., add a sampler item with your sound at the beginning of the experiment, and set the duration to 0)

    Duration indicates the duration of the sampler item, before the next item is presented. This doesn't need to match the length of the sound file. For example, if the duration of the sampler is set to 0 ms, OpenSesame will advance directly to the item that follows the sampler (e.g., a sketchpad), while the sound file continues playing in the backgroundSound // OpenSesame documentation

    It should work as expected, but let us know if you encounter any problems.

    Claire

  • Hi, @cvanbuck

    Yes, already tried.

    The BGM is played, but it is not played repeatedly from the first of BGM.

    I know that repeating music is possible by adding codes in inline_script after the sampler as below.

    import pygame
    
    pygame.mixer.init()
    pygame.mixer.music.load(pool['AddYourOwnBGM.wav']) 
    
    pygame.mixer.music.play(-1)# repeat music when it ends
    

    My question is how we can do that without inline_script.


    Thanks

  • Hi @rrr

    If you're looking to repeat background music without using any inline_script, a simple workaround is to create a longer audio file e.g., by using Audacity to copy-paste the tracks multiple times, re-arranging them as you like. Then, play this extended file at the beginning of your experiment using a sampler item set to duration 0, so it continues in the background.

    It’s not as elegant as looping via code, but it can work well if the experiment has a fixed duration or if you use a long enough audio file to cover the max duration of your experiment.

    Another workaround would be to add multiple sampler items at different points in your experiment where you estimate the audio might end, to re-trigger the playback without scripting. Again, not as elegant as code, but can work well if your estimations are accurate.

    Hope this helps,

    Claire

  • Hi @cvanbuck ,

    Thank you for the information! This discussion is very helpful for every researchers to make experiments with BGM.

    There are 3 options for repeating BGM;

    1. Adding pygame codes in inline_script after the sampler item as described above.
    2. Creating longer audio file as auditory stimulus that have enough time for experiments
    3. Adding multiple sampler items at different points

    Thanks a lot

Sign In or Register to comment.