Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

JMF application still not stopping

  • 09-03-2006 05:24PM
    #1
    Closed Accounts Posts: 27


    I posted here before about my JMF application not stopping..I figured out the problem with what I was doing wrong then. So Ive changed the code. The buttons do work cos I tested them by printing statements. It sill plays but doesnt stop. Any suggestions would be greatly appreciated.

    public void actionPerformed( ActionEvent e )
    {
    try
    {
    String url= "file:RedDawn.mp3";
    MediaLocator mediaLocator= new MediaLocator(url);
    Player mp3Player = Manager.createPlayer(mediaLocator);

    if ( e.getSource() == btPlay_Button )
    {
    mp3Player.start();
    }

    if ( e.getSource() == btStop_Button )
    {
    // Action for btStop_Button
    mp3Player.stop();
    mp3Player.deallocate();
    mp3Player.close();
    }
    }
    catch (Throwable t)
    {
    t.printStackTrace();
    }



    //notice that all the code is inside a try and catch.. this is because Player mp3Player = Manager.createPlayer(mediaLocator); must be declared thrown or caught


Comments

  • Registered Users, Registered Users 2 Posts: 1,275 ✭✭✭bpmurray


    The problem is that you're creating a *new* player each time, so you can never stop the one that's playing. Here's a really simple class that does what you want. The important part is that you only ever have a single player running.

    One thing - I'm pretty certain that you need a separate player class that will catch events such as the end of the file.


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Why use ...
    catch (Throwable t)
    {
    t.printStackTrace();
    }
    

    as far as I can tell your catching errors as well which is inefficient. Should be Exception and and Throwable.


Advertisement