Building a music player

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
rado
Posts: 5
Joined: Tue May 25, 2021 9:33 am

Building a music player

Post by rado » Tue May 25, 2021 9:51 am

Hello guys,

I want to build a music player with LiveCode. Could you please give me some advice on how to approach things or give me some reference examples.
The goal is that the user can select his songs from a dropdown list, add them to to a playlist (scrolling list field) where he can change the songs order and choose where to start playing.
Also I want it to display the duration of all the songs combined and things like bpm etc. which are stored in a table in MySQL.
Currently I am trying to do it with a DataGrid, which is not visible.
Whenever the user selects a song from the dropdown and adds it to the playlist - the songs is also inserted in the DataGrid, where I also store more information about it like the path/link of the song.
But I am finding it difficult to somehow synchronize them both. -> for example to keep the order the same, whenever the user reorders songs in the playlist.

Best regards,
Rado

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Building a music player

Post by dunbarx » Tue May 25, 2021 2:26 pm

Hi.

Never done anything like this, but do go to the dictionary and start reading all about anything with "play" in it. The other stuff is standard LC, and if you need help with that let us know.

There are others that will chime in about playing music files.

But what does this mean:
Currently I am trying to do it with a DataGrid, which is not visible.
Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Building a music player

Post by jacque » Tue May 25, 2021 9:33 pm

A datagrid is overkill for this. It would be much easier to manage a regular LC field. You can set the tabstops to make it look like a grid if you need to, and it's much easier to parse each line, move them around, etc.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

rado
Posts: 5
Joined: Tue May 25, 2021 9:33 am

Re: Building a music player

Post by rado » Thu May 27, 2021 8:57 am

Sorry, i should have been more specific.
By invisible DataGrid, i mean that the grid is not visible for the user.
Whenever the user builds his playlist(selects songs from the dropdown and adds them), only the song title is inserted into the scrolling list field and more detailed information about the selected song is inserted in the data grid-which stays invisible in the background like: bpm, time, path/link etc.
I have attached a photo from my testing stack.

Thank you both for the input, i will continue to read and try stuff out.


Best regards,
Rado
Attachments
MusicPlayerLC.png

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Building a music player

Post by richmond62 » Thu May 27, 2021 9:24 am

I find datagrids far too complex and go for tableFields in a big way.

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Building a music player

Post by stam » Sat May 29, 2021 8:41 am

I may have misunderstood the premise, but not sure why a data grid or even a normal field is required, if invisible to the user.

I would have thought using an array would achieve the same end result and be much faster? (there is a bit of speed penalty using the data grid).

From the developer point of view, you could use a tree widget to get a graphical representation of the array if that's needed.

The array would basically do exactly the same as the data grid and can be re-ordered as needed, eg if your array is musicA, it would look like this to resemble the image of the DG shown:
musicA[1]["music_fileName"]
musicA[1]["music_time"]
musicA[1]["music_bpm"]

musicA[2]["music_fileName"]
musicA[2]["music_time"]
musicA[2]["music_bpm"]

...

musicA[n]["music_fileName"]
musicA[n]["music_time"]
musicA[n]["music_bpm"]

where the integer key (1,2...n) is basically equivalent the row in the data grid and represents order of this associative (multi-dimensional) array. You can re-order easily, just search the forum for 'sort multidimensional array' there have been many discussions about this...

Now having said that, i'm not sure i understand what the OP is trying to 'synchronise', but it's probably just a matter using the array to determine order...

rado
Posts: 5
Joined: Tue May 25, 2021 9:33 am

Re: Building a music player

Post by rado » Tue Jun 01, 2021 10:22 am

Stam,

thank you very much!
Yes DataGrid was obviously a overkill.. I am trying to do it with arrays now.
Forget about the synchronise part.. :D


Best regards,
Rado

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Building a music player

Post by richmond62 » Tue Jun 01, 2021 11:06 am

overkill
Or a scrolling list field.

dalkin
Posts: 176
Joined: Wed Jul 04, 2007 2:32 am
Location: Blackheath, Australia
Contact:

Re: Building a music player

Post by dalkin » Thu Jun 03, 2021 5:05 am

Screen Shot 2021-06-03 at 2.01.01 pm.png
This might help, depending on how you get the files into your app in the first place. This is a little thing that will let you import from your HD into a scrolling list field then put the selected file into the player:

On select files for import:

Code: Select all

on mouseUp
  answer folder "Choose the folder containing the sound files?"
  if the result is not cancel then
     set the cSoundFilesFolder of this card to it
     set the defaultFolder to it

     put the files into tFiles
     put return before line 1 of field "playlist"
     put the files into line 1 of field "playlist"
     filter lines of field "playlist" with regex pattern "(?i)\.(wav|aif|wmv|mp3|wma)$"
  end if
end mouseUp
On select file for play:

Code: Select all

on mouseUp
   put the selectedText of me into tFile
   set the filename of player "P2" to (the cSoundFilesFolder of this card & "/"& tFile)
   put the cUserDefinedName of me into tUserDefindName
  start player P2
end mouseUp
If we're treading on thin ice, well you might as well dance.

YousufAllen
Posts: 1
Joined: Mon Feb 20, 2023 8:11 pm

Re: Building a music player

Post by YousufAllen » Mon Feb 20, 2023 8:14 pm

rado wrote:
Tue May 25, 2021 9:51 am
Hello guys,

I want to build a music player with LiveCode. Could you please give me some advice on how to approach things or give me some reference examples.
The goal is that the user can select his songs from a dropdown list, add them to to a playlist (scrolling list field) where he can change the songs order and choose where to start playing.
Also I want it to display the duration of all the songs combined and things like bpm etc. which are stored in a table in MySQL.
Currently I am trying to do it with a DataGrid, which is not visible.
Whenever the user selects a song from the dropdown and adds it to the playlist - the songs is also inserted in the DataGrid, where I also store more information about it like the path/link of the song.
But I am finding it difficult to somehow synchronize them both. -> for example to keep the order the same, whenever the user reorders songs in the playlist.

Best regards,
Rado
Please let me know if you managed to implement this project. I want to do something similar.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”