Music app

152 views
Skip to first unread message

Kelechi Ekezie

unread,
Jul 4, 2021, 4:24:03 PM7/4/21
to DroidScript
Ok so I created a music app and I created a Next button and I set the button on touch 
Then I used
function btnNext_OnTouch() {
player.Next()} 
But I got the error player.Next is not a function 
Note that player.Play, player.Pause and player.Stop works fine though. 

T. Lee

unread,
Jul 4, 2021, 6:01:31 PM7/4/21
to DroidScript
Well, 'Next' is not a method of the MediaPlayer component. https://symdstools.github.io/Docs/docs/app/CreateMediaPlayer.htm

How would the MediaPlayer know what file to play next? You would likely need to maintain a playlist and upon btnNext_OnTouch:
player.Stop
player.SetFile([the-next-file-in-the-list])
player.Play

Kelechi Ekezie

unread,
Oct 19, 2021, 9:43:29 AM10/19/21
to DroidScript
Can u give  a sample code regarding how to set the next file in list please
Thanks in advance

Alan Hendry

unread,
Oct 19, 2021, 10:29:37 AM10/19/21
to DroidScript
Hi,
First you'd need a list of music files
Second create the media player and setfile (first music file in the list) 
Third set index to zero
   index = 0
Fourth a button with OnTouch (Next)
In the OnTouch
   add 1 to index
   if index is greater than list.GetLength then index = 0
   Retrieve from the list GetItemByIndex(index), SetFile on the Media Player
Regards, ah

Kelechi Ekezie

unread,
Oct 19, 2021, 3:16:06 PM10/19/21
to DroidScript

Am even more confused
Would you be kind enough to write this code for me, pls
Regards, ah

Alan Hendry

unread,
Oct 20, 2021, 10:32:53 AM10/20/21
to DroidScript
HI,
Probably the easiest way is to copy a Sample and modify it
Touch the rocket icon in the top-right, scroll down to Audio Player, touch it, then touch the left-bottom  icon, then paste into a new app.
Change Spinner to List
spin = app.AddList( lay,"[No tracks found]" );
player.SetFile( p + "/" + spin.GetItemByIndex(0).title );
After the block of code for the Stop Button add code for a Next Button
//Create 'Next' button.
btnNext = app.CreateButton( "Next", 0.4, 0.1 )
btnNext.SetOnTouch( btnNext_OnTouch )
lay.AddChild( btnNext ) 
        index = 0
After the btnStop functon add 
//Handle 'Next' button.
function btnNext_OnTouch() {
index += 1
if (index >= spin.GetLength() ) index = 0;
alert(p + "/" + spin.GetItemByIndex(index).title)
player.SetFile( p + "/" + spin.GetItemByIndex(index).title );
}
If you have got a lot of music (in the music folder) the screen will be overfull, 
so you could hide the list, or use a scroller.
Regards, ah

ECEisLife

unread,
Oct 20, 2021, 9:41:31 PM10/20/21
to DroidScript
Hi

Playing the next or previous file requires you to have a basic understanding of javascript arrays.

I created a public project of Music Player which you can read here

Or you can view the code on GitHub here

Regards
Jumar
Reply all
Reply to author
Forward
0 new messages