Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

JMF application still not stopping

  • 09-03-2006 4: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