Howdy, Stranger!

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

Supported by

Loading external stimuli (images and sound) in an OSWeb experiment

Hi everyone,

At the time of writing, OSWeb 1.3.13 does not provide a convenient way to load stimuli (images or sounds) from a URL. This is inconvenient when running experiments that require a large number of stimuli, in which case including all stimuli in the file pool is impractical. (We recommend keeping the size of the .osexp file below 10 Mb for online studies.)

For now, the script below can serve as a workaround. It defines two functions addExternalImageToPool() and addExternalSoundToPool() which both take a url and a name as arguments. The url is a link to the stimulus file. The name is the name under which the stimulus is added to the file pool.

There are two crucial caveats to this approach:

  • The server on which the stimuli are hosted must allow cross-origin resource sharing (CORS). This means that the server allows its files to be read by scripts that were hosted by other servers. Most servers do not allow this, in which case you get an error message that refers to the CORS policy. This error message silently appears in the browser console, and the stimulus will simply not be shown. Conveniently, raw.githubusercontent.com does allow this, and therefore I used these links in the example below.
  • The stimuli require a short period to be loaded. This occurs in the background. If you try to use the stimuli before they are loaded, they are not presented (no error message seems to be generated for this).

Hopefully this is useful!

— Sebastiaan

function addExternalImageToPool(url, name) {
    const img = new Image()
    img.crossOrigin = "anonymous"
    img.src = url
    const item = {
        data: img,
        type: "image",
        name: name
    }
    runner._pool.add(item)
}

function addExternalSoundToPool(url, name) {
    const snd = new Audio()
    snd.crossOrigin = "anonymous"
    snd.src = url
    const item = {
        data: snd,
        type: "sound",
        name: name
    }
    runner._pool.add(item)
}

addExternalImageToPool(
    "https://raw.githubusercontent.com/open-cogsci/OpenSesame/loewenfeld/opensesame_plugins/joystick/joystick.png",
    "joystick.png"
)

addExternalSoundToPool(
    "https://raw.githubusercontent.com/open-cogsci/OpenSesame/loewenfeld/opensesame_resources/sounds/sonar.ogg",
    "bark.ogg"
)

Ping @eduard @lvanderlinden @Daniel

Buy Me A Coffee

Comments

  • Hi @sebastiaan ,

    Thanks for this! Interesting method! And inspiring too!

    I was wondering whether it might actually be modified to solve the current lack of option to populate loops from a file...

    I had worked out a way of dealing with this limitation (see here) but it can be fairly heavy and cumbersome. Reading your post, I wondered whether something similar might possibly be used to read a csv directly from a URL and then populate an array based on its content. I came across this post that refers to the use of "new XMLHttpRequest()" to read a csv file. I'm not experienced enough to solve it yet, but I was curious to know whether you think that in principle it may be possible or knew of some coding that might be useful to achieve this.

    Any opinion or hint would be much appreciated.

    All the best,

    Fabrice.

    Ping @eduard @lvanderlinden @Daniel

    If you found my reply helpful and wish to invite me to a coffee, you can do so here πŸ˜‰ Buy Me A Coffee

  • Hi Fab,

    Just to give you some response, I simply have no idea :)

    What you say seems to make sense, but I have no clue whether it actually does, nor can I help you finding out.

    Good luck in any case and post your solution in case you find one.

    Eduard

    ps. thanks for being so active here! It really helps a lot.

    Buy Me A Coffee

  • Hi @eduard,

    Thanks for your reply!

    I too think it might be possible, but I have no clue how at the moment. Perhaps I'll look into it at some point (though it'd be great to see that feature implemented in a future update of OSWeb; that and possibility of playing video files and use something like the forms to collect text responses). If I find a solution, I'll post it on the forum.

    Best,

    Fabrice.

    PS: you're welcome; I started trying to solve other people's queries as a way to learn OS myself. Have been working E-Prime for many years, which I'm happy with in the lab, but I found Eprime-Go unpractical for online testing, so finally decided to look into something else. I think OS and OSWeb are fantastic tools, and free to use, which is great.

    If you found my reply helpful and wish to invite me to a coffee, you can do so here πŸ˜‰ Buy Me A Coffee

  • Hi @Fab and @eduard ,

    Thanks for thinking along! There are two more-or-less separate things here.

    The first is the option to use a file as a source for a loop table. This is something that I'd definitely like to implement, but since this source file would usually be part of the file pool it's not directly related to the ability to read external files (i.e. that are not in the file pool).

    The second is the option to allow arbitrary URLs as the source for images, sound files, and files that are used as sources for the loop table. For this, some variation of the hack described in this post should probably be implemented in OSWeb.

    It's on the radar!

    — Sebastiaan

    Buy Me A Coffee

  • Thanks @sebastiaan ! That sounds very exciting!

    I agree, these are two separate issues. My guess is that many users would make use of such functions.

    Look forward to seeing it implemented at some point in the future πŸ‘οΈ

    Thanks for your and the team's hard work on OS and OSWeb!

    Fabrice.

    If you found my reply helpful and wish to invite me to a coffee, you can do so here πŸ˜‰ Buy Me A Coffee

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games