Audio Player
How to build Audio Player?
Audio Player made in Script Language of DroidScript in very Easy with short codes. I give you an example but completely different in various method. buy the way, codes are never used in any program or app before I send it to my web post.
Thanks you for all Reader's.
Audio Player version 1.0
Coding Start here....
//Create fixed or non fixed variables.
var destFile =0;
var timer =0;
var dur,prog;
//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" )
lay.SetBackColor( "#ffffcc" )
layBut= app.CreateLayout( "linear", "Horizontal,FillX" )
layBut.SetBackColor( "#000001" )
layBut2= app.CreateLayout( "linear", "Horizontal,FillX" )
layBut2.SetBackColor( "#f3ff11" )
layBott= app.CreateLayout( "linear", "VCenter,FillX" )
layBott.SetBackColor( "#11ff11" )
//Header text
ttp2 =app.CreateText( "" )
ttp2.SetTextColor( "#ff3300" )
layBott.AddChild( ttp2 )
//Create a 'Stop' button.
btnStp = app.CreateButton( "[fa-stop]", 0.2, -1, "FontAwesome,Alum,NoSound" )
btnStp.SetOnTouch( btnStp_OnTouch )
layBut.AddChild( btnStp )
//Create a 'pause' button.
btnPaus = app.CreateButton( "[fa-pause]", 0.2, -1, "FontAwesome,Alum,NoSound" )
btnPaus.SetOnTouch( btnPaus_OnTouch )
layBut.AddChild( btnPaus)
//Create a 'Play' button.
btnPlay = app.CreateButton( "[fa-play]", 0.2, -1, "FontAwesome,Alum,NoSound" )
btnPlay.SetOnTouch( btnPlay_OnTouch )
layBut.AddChild( btnPlay )
//Create a 'File Open' button.
btnOpen = app.CreateButton( "[fa-file]", 0.2, -1, "FontAwesome,Alum,NoSound" )
btnOpen.SetOnTouch( btnOpen_OnTouch )
layBut.AddChild( btnOpen )
//Create seek bar and add to layout.
skb = app.CreateSeekBar(0.9, -1 )
skb.SetMargins( 0, 0.05, 0, 0)
skb.SetRange( 1.0)
skb.SetOnTouch( skb_OnTouch )
layBott.AddChild( skb )
txtDur=app.CreateText( "")
layBott.AddChild( txtDur )
//duration
ttp=app.CreateText( "0.00",0.2,-1 )
layBott.AddChild( ttp )
//Add layout to app.
lay.AddChild( layBut2 )
lay.AddChild( layBott )
app.AddLayout( lay )
lay.AddChild( layBut )
rec = app.CreateAudioRecorder()
//Create media player.
player = app.CreateMediaPlayer()
player.SetFile( destFile )
player.SetOnReady( player_OnReady )
//Switch off debug so we don't fill the log.
app.SetDebugEnabled( false )
//Start timer to update seek bar every second.
setInterval( "Update2()", 100 )
}
//Called when user touches our 'Pause' button.
function btnStp_OnTouch()
{
player.Stop()
}
//Called when
function btnPlay_OnTouch()
{
player.Play();
}
function btnPaus_OnTouch()
{
player.Pause();
}
//Called when the WAV file is loaded.
function player_OnReady()
{
app.ShowPopup( "Please Open Audio File")
}
function skb_OnTouch(value)
{
player.SeekTo(dur*value);
}
//Update seek bar.
function Update2()
{
dur =player.GetDuration()
prog =player.GetPosition();
if (dur){ skb.SetValue( prog/dur);
ttp.SetText(prog);
txtDur.SetText( dur )
}
}
function btnOpen_OnTouch()
{
app.ChooseFile( "Choose a file", "*/*", OnFileChoose )
}
//Called when a file is chosen.
function OnFileChoose( file)
{
player.SetFile(file)
ttp2.SetText( file )
app.ShowPopup( fileName )
}
End here....
0 Comments