Playing MP3 file from resources

Playing MP3 file from resources

  

Hello,

I am currently working on a mobile app to play different mp3 files which are stored in the resources.

I am not experienced with OutSystems so I searched the forum and found a pre-written JavaScript-Code to play a mp3 file. The problem is that it requires an URL for the file and I don't know how to put the local resource file in there.

I am glad for every help.

Paul

Hello Paul,

in your URL you will have to pass the Runtime Path of the resource which you can easily get under file properties under Resources.


Use something like

var filePath= '/{your_application_name}/{filename.extension}';


Hope this helps :)

Thanks and Regards,
Atul Patel

Atul Patel wrote:

Hello Paul,

in your URL you will have to pass the Runtime Path of the resource which you can easily get under file properties under Resources.


Use something like

var filePath= '/{your_application_name}/{filename.extension}';


Hope this helps :)

Thanks and Regards,
Atul Patel

Hello Atul,

thanks for your reply. I tried it out but on my preview it doesn't play any sound. Is this because of the code or because of the preview, OutSystems provides?


I put my latest code below, it would be great if you have another look at it!


Regards, Paul



function Sound(source,volume,loop)
{
    this.source=source;
    this.volume=volume;
    this.loop=loop;
    var son;
    this.son=son;
    this.finish=false;
    this.stop=function()
    {
        document.body.removeChild(this.son);
    }
    this.start=function()
    {
        if(this.finish)return false;
        this.son=document.createElement("embed");
        this.son.setAttribute("src",this.source);
        this.son.setAttribute("hidden","true");
        this.son.setAttribute("volume",this.volume);
        this.son.setAttribute("autostart","true");
        this.son.setAttribute("loop",this.loop);
        document.body.appendChild(this.son);
    }
    this.remove=function()
    {
        document.body.removeChild(this.son);
        this.finish=true;
    }
    this.init=function(volume,loop)
    {
        this.finish=false;
        this.volume=volume;
        this.loop=loop;
    }
}

var foo=new Sound("/IrishLearning/Illusion.mp3",100,true);
foo.start();
foo.stop();
foo.start();
foo.init(100,false);
foo.remove();