• Post Reply Bookmark Topic Watch Topic
  • New Topic

Play Pause Sound in Java  RSS feed

 
ali ak
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I want to do is very clear, just play sound and pause it. The problem is that I can't pause the music. When I click the pause button music keeps playing .I have been working on for 2 hours. I can't find the mistake; what am I doing wrong?
Edit:I am posting all code


 
Campbell Ritchie
Marshal
Posts: 56521
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show us a short bit of code where you are trying to pause the music. That is called an (link→)SSCCE.
Another link which tells you the same:- here.
 
Carey Brown
Saloon Keeper
Posts: 3309
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is an AudioStream and an AudioPlayer? These are not part of standard Java.
 
Carey Brown
Saloon Keeper
Posts: 3309
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have several blocks of IF, IF, IF, IF that should be IF, ELSE-IF, ELSE-IF, ELSE-IF.
 
ali ak
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry.I know I shouldnt post all the code . But I cant find any solution for 2 days and .I thouht if I post all the code It might be helpfull someone who wants to test it .
 
Tony Docherty
Bartender
Posts: 3271
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know the API but there is something odd about starting the player with the audio stream and stopping it with the file input stream. Shouldn't you be calling stop() and passing in the audio stream and not the file input stream.
 
ali ak
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes my friend I have also realized that .But I havent changed until you point out. Because this was a small part of project that I found on the net .SoI thouht I must be like this way .But you are absolutely right.Thank you so muchh
 
Carey Brown
Saloon Keeper
Posts: 3309
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was the the only link I could find on playing MP3's with a pause capability. Probably using a different library than you a currently using: JLayer.
how-to-play-pause-a-mp3-file-using-the-javazoom-jlayer-library
 
ali ak
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tjank you for link
 
Carey Brown
Saloon Keeper
Posts: 3309
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was playing around with the JLayer library and I had to tweak it like this to get it to resume at the same place. It seems that event.getFrame() returns milliseconds and not frames. A "typical" MP3 has about 27ms per frame. If you could get access to the MP3's metadata you could verify this by looking at the sampling rate and samples per frame. Also, getFrame() does not return the absolute position in the MP3 but the position relative to the start point, which is different if you've already done a pause-resume, hence the increment (+=).

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