Back

PlaySound

Hello World

Plays a sound file stored remotely or on the local filesystem.

app.PlaySound( file )

See Also: CreateMediaPlayer

Example - Play Local Sound File

function OnStart(){
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );

    btn = app.CreateButton( "Press Me", 0.3, 0.1 );
    btn.SetOnTouch( btn_OnTouch );
    lay.AddChild( btn );

    app.AddLayout( lay );
}

function btn_OnTouch()
{
    app.PlaySound( "/Sys/Snd/Trill.ogg" );
}
    Copy     Copy All       Run      

Example - Play Remote Sound File

function OnStart(){
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );

    btn = app.CreateButton( "Press Me", 0.3, 0.1 );
    btn.SetOnTouch( btn_OnTouch );
    lay.AddChild( btn );

    app.AddLayout( lay );
}

function btn_OnTouch()
{
    app.PlaySound( "https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3" );
}
    Copy     Copy All       Run      
string: path to file or folder ( “/absolute/...” or “relative/...” )
string: url path