Playing a mp3, how do i pause / stop?

I will start out, saying that I've never written my own thread before, and I'm extremely novice in that area. But I found some code for playing an mp3, that's going to be invoked from a JLayeredPane(that i used to make a little animation sequence.) I can't figure out how to stop the player without calling stop on the thread which is apparently depreciated. Might be off this forums area, but from my swing component, should I be calling this thread with invoke? or invoke and wait. this thread doesn't need access to the swing component, but from the swing thread, I want to be able to stop the player. So here's the code I found
import javax.media.*;
import java.io.*;
import java.net.URL;
class mp3 extends Thread
  private URL url;
  private MediaLocator mediaLocator;
  private Player playMP3;
  public mp3(String mp3)
    try
     this.url = new URL(mp3);
      catch(java.net.MalformedURLException e)
        System.out.println(e.getMessage());
  public Player getPlayer()
    return this.playMP3;
  public void run()
    try
      mediaLocator = new MediaLocator(url);    
      playMP3 = Manager.createPlayer(mediaLocator);
    catch(java.io.IOException e)
      System.out.println(e.getMessage());
    catch(javax.media.NoPlayerException e)
      System.out.println(e.getMessage());
    playMP3.addControllerListener(
      new ControllerListener()
        public void controllerUpdate(ControllerEvent e)
          if (e instanceof EndOfMediaEvent)
            playMP3.stop();
            playMP3.close();
    playMP3.realize();
    playMP3.start();
public class playmp3
  public static void main(String[] args)
    mp3 t = new mp3("file:///C://Beat1.mp3");
    t.start();
}

You just need to write a stop and a pause function as part of the MP3 class, and make sure it's a syncronized function (if you don't know what this means, look up the Java keyword syncronized).

Similar Messages

  • How do i pause/stop something running in the background?

    I'll try to give as many details as I can:
    I am using an auto clicker program (quick keys x), and I copied and pasted 150 or so of the same mouse recording, each lasting around 5 minutes. I want them to run, but I need to know how to pause them whenever. I didn't change any of the hot key options or anything. The program that is up and running (that I see listed in the top left corner) is google chrome. I want that to stay up while the auto clicker is running. The top right has a thing with a Q, pause symbol, and a stop symbol. That's where it's running, and I want to know how to pause that (or stop if neccesary) without closing google chrome at all.
    If you have any questions on the situation, please ask, I need all the help I can get!
    Thanks!

    I usually just kill the process.  If I know a specific app is running in the background, say "iPhoto", and I can't close it normally, I open a terminal and type:
    ps -A | grep iPhoto
    then i kill the proccess id with:
    kill -9 ###
    where ### is the process id.  you might need to add a sudo before that if root access is required:
    sudo kill -9 ###

  • I need to play a song on a Keynote presentation, how do I do this ? I use to drag and drop the mp3 in Keynote but it stops playing when the slide move to the other one... how can I make the song keep playing through the whole presentation ? Thanks.

    I need to play a song in a row in a Keynote presentation, how do I do this ? I use to drag and drop the mp3 in Keynote but it stops playing when the slide move to the other one... how can I make the song keep playing through out the presentation ?
    Thanks.

    Drag the file into the audio window in the Document inspector...

  • Why does my playhead return to the initial position when pausing/stopping playback after playing from beginning?

         How do I prevent the playhead from returning to it's original position after pausing or stopping with the spacebar or k button?  With either the skimmer on or off, whenever I pause or stop the **** playhead will always return to the position it was last at.  I don't understand why neither of the shortcuts would just stop the playhead at the point that is being played at.  This may seem like an extremely edgy way to go about editing, but I might actually wish to pause the playhead at any given moment and position my playhead nearby said moment before creating an edit point (without having to add a marker and return to it with the blade tool, or take note of the specific duration and use the duration control to go to that specific point or any other unnecessary steps when doing a rough cut).  I simply would like the playhead to pause/stop at the moment I press either keyboard shortcut.  After the many attempts at trying to make FCP X work for me and the many "workarounds" by FCPX enthusiasts, it's disheartening to know that most other editors in my circle who make a living doing paid commercial work are wondering why I've decided to take a break from using CS6 (and it's integration with the industry-standard AE) to give FCP X a shot, all to make very simple tasks like the one aforementioned a mystery...  any help in this matter would be greatly appreciated.

    Thank you for your response Luis and for your previous help (regarding multiple selections being added to the timeline in reverse order when working in list view in the event browser).
    Yes i've trashed my preferences, but I should be more specific as to what I am actually doing.  Because I am working from my macbook pro and do not have a "home button" which was the original shortcut to "play from/go to beginning" and because I did not like the replacement shortcut in FCP X to play from beginning (without a home button it was something like Function + Shift something else on a laptop) I became used to Adobe Premiere CS6 and made the return key my "play from beginning" shortcut.  It was available and did not have a use by itself (only to confirm changes/choices), did not effect it's use in conjunction with other shorctus so I choose enter as my "play from/go to beginning"...
    So when I play from the beginning and attempt to pause or stop the playhead, regardless of how I choose to do it (spacebar or k) it does not stop at that specific instance and always returns to where it previously was.  This seems very confusing and inconvenient, I would hope at least one of these shortcuts would actually stop the playhead where it was at that moment where I press stop or pause.  It's extremely frustrating knowing that I cannot pause the playhead where it's playing if I choose my "play from beginning" shortcut.
    Also since you seem to be a guru and an expert, i'd like to know if you cut with FCPX on a laptop and what shortcut you use whenever you'd like the playhead to go to the beginning of the timeline, end, etc since there are no "home" or "end" buttons on a laptop....
    Thanks a million, talk soon...
    Anthony

  • Playing, Pausing, Stopping Audio in a Timeline

    I don't use Flash that much so the question may sound simple, but how do I pause audio in a timeline?  I have added the audio, play and stop button.  When I test it works fine, but I can't figure out how to add the pause button, or the play/pause button.
    Thanks.

    Set the audio options on "stream" for the timeline. Then - a blank keyframe would do just fine. When you need the audio on, put it again and adjust the start point in the properties panel.
    Emil Georgiev - Flash and Web Design

  • How can I get itunes on my i pad to play single songs in a playlist without stopping it manually?

    How can I get itunes on my i pad to play single songs in a playlist without stopping it manually?

    To turn on the check marks on, say, 150 consecutive songs in a list, do the following:
    Click on the first song in the list.
    Scroll to the last (150th) song in the list.
    Hold the shift key down while clicking the last song in the list.
    All 150 songs will then be highlighted.  Click the check box in one of the 150 songs and all songs will exhibit the same behavior.

  • How to simply play one mp3 at a time without a playlist or duplicate file creation

    What's always baffled me about Itunes is the overkill factor for we who are media professionals and simply need
    to be able to select and playback an audio file - without the proprietary architecture of the whole "Playlist" format...
    and, as long as we're at it, without automatically having a duplicate of whatever is being played, created and placed
    in a new folder somewhere. 
    "Back in the day..."  I could take SoundJam - (actually the predecessor app that Itunes was originally based upon)
    --which i still regularly use for easy conversion of .aifs to .mp3s --  and select/play any number of mp3s located in a
    single file folder at random.  No "playlist" was created or needed -  and it didn't/doesn't dupe a copy of the file.
    Can i in any way scale down or customize Itunes in a way that i can just play each mp3 in a given folder by selecting
    it 'directly' and not have to have it generate a playlist "copy" -  My use for Itunes as far as commercial production is
    for quick review/play of sound elements, spots (commercials) audio clips, etc. For this I'm not looking to "order" or
    organize anything, just simply start/stop an audio cut and move to another. 
    Alternately, any suggestions on simpler practical alternative 3rd party apps... Stuff like "Vox" comes kinda close but
    i still have to drag and drop the icon of the audio file onto the app's icon to initiate play.  Still, at least it doesn't force
    me into a Playlist or generate a copy just by selecting and playing the cut.
    If this makes sense to anyone I'd really appreciate any ideas,
    Thanks!

    MIKEinMICH wrote:
    Can i in any way scale down or customize Itunes in a way that i can just play each mp3 in a given folder by selecting it 'directly' and not have to have it generate a playlist "copy" -  My use for Itunes as far as commercial production is for quick review/play of sound elements, spots (commercials) audio clips, etc. For this I'm not looking to "order" or organize anything, just simply start/stop an audio cut and move to another. 
    In a Finder window, select a song and press the Space bar.

  • When updating iPhoto, a pop up said "pause", stopped the update and this is where iphoto now is stuck. How do I get it unstuck?

    When updating iPhoto, a pop up said "pause", stopped the update and this is where iphoto now is stuck. How do I get it unstuck?

    Welcome to the Apple Support Communities
    If you were updating iPhoto from the App Store, open Launchpad and click your iPhoto icon, so download should continue. If it doesn't work, restart your computer, delete iPhoto and install it again

  • Using default CS5 skin, play/pause & stop buttons disabled until going fullscreen

    We are using default CS5 skins with an flvplayback component built through action script 3.  When playing certain videos (and only certain videos, however there isn't yet a pattern), the play/pause, stop & seek buttons are completely unresponsive.  They don't change stats on hover & they are unclickable.
    However, the fullscreen button does always work, and upon going fullscreen and coming back out, the buttons now work again.
    I really have no idea what is going on here, it seems rather random.  So far, the problem was seemingly at its worst displaying a video that was encoded with Sorenson spark (an older codec) and we wondered if it had to do with the file itself, the headers, anything of that sort.  But the fact that the skin and buttons work fine once entering and exiting fullscreen - that is perplexing.

    Just an update, but the following line:
    my_FLVPlybk.scaleMode = "noScale";
    Has something to do with the issue.  When we include this line (which tells the player to resize to the size of the given FLV), we get the problem with the buttons not working.  If we take the line out, we do not see that problem.

  • Easy Question! How Do I Play ONLY the Selection, and then playback stops?

    How Do I Play ONLY the Selection, and then playback stops? (Same as subject..)
    Thanks! I'm loving STP so far. I came from Sony Sound Forge so it's been difficult finding something that can compare, but I think I have it now! Lot's of advantages for STP too.

    I think you're confusing the audio loops with MIDI loops. The blue loops are audio loops which will play only on audio tracks. You can't 'play' those with a keyboard because they are actual audio files. The green loops contain MIDI data that corresponds with a software instrument, and if you drop them onto a Software Instrument track, they will open that instrument which you CAN play with an external keyboard or the caps lock keyboard.
    I might be missing some loops, but when I searched for Bell Tower I found only one, and it is a blue loop. So it can only be played as an audio loop on an audio track. However, if it were a green loop, you would NOT drop it on an external MIDI track (I think that's what you're trying to do if you're dragging it onto the 'Grand Piano MIDI instrument'), but you would create a SOFTWARE INSTRUMENT track, and drag it on that. Any internal sounds you want to play from Logic's instrument you'll do from Software Instrument tracks, and not MIDI tracks.
    What you should do to find a good chime sound that you can play with the caps lock keyboard is to create a Software Instrument Track, open the Library tab, and search there for a good chime. This will search all of the instruments and presets that Logic has for all of its internal instruments. Try 'Tubular Bells' and see if that works for you.
    If you need to use the bells from that loop, do what SC suggested, and take the hits from the audio file and load them into a sampler. Then you can play them the way you want to. If you don't know how to make a sampler, it's a bit complicated. Look up EXS24 in the manual, or check out
    http://www.youtube.com/user/SFLogicNinja
    I think he has a video or two on EXS24

  • When I play a movie in iDVD, how can I pause to return to main menu?

    When I play a Quicktime movie in iDVD, is it possible to have a progress slider and have controls with play, pause, forward or rewind while playing? Right now, what it does is the movie plays entirely and returns to main menu after playing.
    Also, how can I return to main menu even if the video hasn't entirely played?
    Thanx in advance!
    Serge

    When I play a Quicktime movie in iDVD, is it possible to have a progress slider and have controls with play, pause, forward or rewind while playing? Right now, what it does is the movie plays entirely and returns to main menu after playing.
    No, not in iDVD - Have you tried the controls on your DVD player remote - that's what I do.
    Also, how can I return to main menu even if the video hasn't entirely played?
    I just hit the 'Menu' button on my DVD player remote.

  • TS3297 I bought an album, two of the twelve songs play about half the way through, then stop, and then the next song in line starts playing.  How do I get the songs downloaded so they play to the end?

    I bought an album, two of the twelve songs play about half the way through, then stop, and then the next song in line starts playing.  How do I get the songs downloaded so they play to the end?

    Welcome to the Apple Community.
    Try deleting the problematic file (electing to remove original file if/when prompted) and then re-downloading the file from the iTunes store.
    You can re-download content purchased from the iTunes store (availability varies depending on location) using the purchased option from the Quick Links section in the top right corner of the iTunes homepage in your iTunes application on your computer.
    You can re-download content purchased from the iTunes store (availability varies depending on location) using the purchased option at the bottom of the screen of the iTunes app (or video app) on your iOS device.
    If the problem re-occurs, select the content which is causing a problem and use the 'Report a problem' button in Your Purchase History using your computer.

  • HT1725 I have downloaded an album from itunes, and one or two of the songs play in full but most of them stop mid song, even though it said 'download complete'. How do I fix this?

    I have downloaded an album from itunes, and one or two of the songs play in full but most of them stop mid song, even though it said 'download complete'. How do I fix this?

    I'd report the problem to the iTunes Store.
    Log in to the Store. Click on "Account" in your Quick Links. When you're in your Account information screen, go down to Purchase History and click "See all".
    Find the items that are not playing properly. If you can't see "Report a Problem" next to the entries, click the "Report a problem" button. Now click the "Report a Problem" links next to the items.
    (Not entirely sure what happens after you click that link, but fingers crossed it should be relatively straightforward.)

  • When I play songs on my itunes account, they stop after about one minute and itunes goes to the next one.  how do I fix this? These are songs in entire albums that I have purchased.

    when I play songs on my itunes account, they stop after about one minute and itunes goes on to the next song.  This is happening with songs on albums I have purchased direclty through itunes

    Assuming you are in a region where you are allowed to redownload your past music purchases, delete the broken files from your iTunes library, go to the iTunes Store home page, click on the Purchased link from the Quick Links section in the right-hand column, then select Music and Not on this computer. You should find download links for your tracks there.
    If you don't see them straight away it may help to close and restart iTunes.
    While downloading select Downloads in the left-hand column and make sure Allow Simultaneous Downloads is unticked.
    If the problem persists, or that facility is not yet available in your region, contact the iTunes Store support staff through the report a problem links in your account history, or via Contact Support.
    See also: HT2519 - Downloading past purchases from the App Store, iBookstore, and iTunes Store
    tt2

  • Mp3 links no longer stream in firefox 4.0 but it works in 3.6, how can i make 4.0 play a mp3 stream like before

    i dont think this is a problem with the quick time plugin as it works fine on 3.6. is it maybe more the way firefox 4.0 looks at the .mp3 links and only wants to save it? i like the fact you can stream links rather than have to save them first before you can hear them...
    thanks

    Also to add to this, I have tried Microsofts HTML 5 test drive demo on the "HTML5 Audio Player + XML Playlist" section and Firefox 4.0 doesn't play steamed MP3 files from this.
    If it's other streaming formats such as OGG or WAV, then Firefox will play them with no problems.

Maybe you are looking for

  • A part sensor is not working, a part sensor is not working

    dear all...if someone has idea about to exchange iph4s at apple store.My bro bought 4s a couple of months back in Thailand apple stores in cash with his passport.The problem is a part of sensor is not reading and he doesn't hav receipt anymore coz he

  • Differnec in front end and back end of ESS record time from ABAP point

    HI Expert, Here I need information regarding employee working time. Quary is we are trying to restricts the records entered in time sheet through user exit CATS0006. Here in CATS0006 one table is there CHECK_TABLE. when I am executing time sheet from

  • Iweb publishes poor picture quality

    Can anybody help me with this one? When I put in a picture in the size of 1000 x 640 pixels in iweb everything looks fine. But when I then publish it to mobileme and check my site online, it looks horrible. I tried different formats and everything, b

  • Auto mail of purchase order to vendor after final approval(release)

    hello all, my requirement is that.after creation of purchse order and final release,my client want to send the puchase crder automatically to vendor via mail. pls explain me settings for same. i have already search the sdn threads,but not got the exa

  • TOAD for Oracle 11g ?

    Hi ! Can anybody suggest me that, is there any TOAD versions (free versions) which supports Oracle 11g Database ? Thanks in advance. Aji