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://sgarman.net/silly.mp3" );
}
    Copy     Copy All       Run      
String: path to file ( “/absolute/...” or “relative/...” )
String: url path