Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Play music from gui interface, multithreading problem?  RSS feed

 
Alin Andrei
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!
As it's almost Christmas I thought I could make some kind of music player.
First I've created a text file in which I wrote the songs I intend to listen to...then I'm reading these songs and display them into a centered textarea.
Then I made every line from textarea clickable using viewToModel method...first I get the x and y of the Point when I'm clicking then create some kind of row of points with rowStart and rowEnd then I'm just retrieving the line I clicked and display it in another panel(in the left) alongside with a specific play icon
Then when I click on the item that just appeared, the coresponding lyrics should be displayed in another panel from the right that contains a Jtextarea.
Well, I have 2 problems: a big one and a small one...
The big problem is I don't know a proper way to play the song when I click on a specific item from that list...
I tried some kind of library and started playing but stucked all my frame...I mean, there were no chance that I could click on another item and the song start playing, everything stucked just the music was playing
Then I read that java programs can be executed in separate threads...is this the case?
I have a frame with a button and when I click the button I want the textarea gets populated with lyrics and after 10 seconds music to start playing?...Is this a problem specific to multithreading thing?...I've never implemented myself Runnable interface to force my program to run in a separate thread...
Or maybe is the way I've choosen to play the music that's causing me that stucking...I don't know
The second problem which is not so important looks like this.

Whenever I run my program, it loads all the songs from the text file, but at the same is printing the number(the index) of the song in the left of the song's name...so my string is something like this 1. Have yourself a merry little christmas
Then, when I'm retrieving the string it is just like this 1. Have yourself a merry little christmas and it would be laborious to rename all my lyrics files with that pattern No. Song's name so I've used a substring method to get me only the substring starting from index 7 and it works ok...
I'm clicking the string line and it is added automatically to the left panel alongside with that specific icon(26x26 play icon) and when I'm clicking on it right afer I've added from the centered panel, it works but then after I added another item and I'm trying to click the first added item again, it no longer works...it changes the item's name...

To sumarize the small problem...I click on the center panel, adding many items(many songs) to the leftPanel but then I can't click on random item and hope it will really load the correct lyrics textfile in the textarea from the right...this works like this:

I'm adding Jinggle bells from the centered panel to the left panel and click on it; works
I'm adding Jinggle bells from the centered panel to the left panel then I;m adding Silent night from the centered panel and click on the first item( Jingle bells) it no longer works...he sees Silent Night which is already loaded...I think you got the point...maybe the code will make the things clearer.
Thanks a lot in advance!!


Here is my whole bucket code:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!