Skip to content

Suggestion to allow data URL for audio #995

Description

@customautosys

Currently, the audio loader is hard-coded to append the name and extension to the path. However, this does not work with data URLs. It is unfortunate because webpack can automatically generate data URLs for small files, and this has to be disabled in order for the audio files to be loaded by melonjs. The behaviour is also inconsistent with that for pictures.

I would like to suggest having the full URL specified for audio files, similar to pictures. If multiple alternative audio formats are needed, an array of alternative URLs may be provided.

Activity

  1. obiot commented on May 23, 2020

    @obiot
    Member

    wait , unless I'm misunderstanding what you mean, this should be possible, have you seen/tried this :
    http://melonjs.github.io/melonJS/docs/me.loader.html#.setBaseURL

    (maybe give me here one example to be sure we are talking about the same thing)

  2. customautosys commented on May 26, 2020

    @customautosys
    ContributorAuthor

    No, this is not the problem.

    The problem is that when I load the audio files, it automatically adds a ".mp3" to the end of the URL.

    This screws up any files which are webpacked into data URLs.

    Currently audio asset srcs only specify the folder and not the path of the file, as shown in the example on the me.loader page:

    me.loader.load({
        name   : "bgmusic",
        type   : "audio",
        src    : "data/audio/"
    }, function () {
        me.audio.play("bgmusic");
    });
    

    I think you should allow the full path to be specified in src so that small audio files can be automatically webpacked into data URLs which will probably load faster.

  3. obiot commented on May 26, 2020

    @obiot
    Member

    oh I see indeed. Well this was implemented this way so that we could ensure that we only (pre)load audio file actually supported by the device (could be .mp3 in one device/browser but ogg on another device/browser), but sure I guess that we could actually specific a full URL with file extension and in that case skip the audio format detection.

  4. customautosys commented on May 26, 2020

    @customautosys
    ContributorAuthor

    like maybe you can allow an object to specify the format?

    e.g.

    import bla_mp3 from 'bla.mp3';
    import bla_ogg from 'bla.ogg';
    
    ...
    
    {
    mp3:bla_mp3,
    ogg:bla_ogg
    }
    ...
    
  5. locked and limited conversation to collaborators on Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions