Page 3 of 7 FirstFirst 1234567 LastLast
Results 21 to 30 of 62

Thread: Building A Completely Java Based Front End

  1. #21
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    Quote Originally Posted by coffeejolts View Post
    I would do it by reading from the input stream until you get to the point that you need, without calling line.write(...). Once you get to the point you need, call line.write(...)
    Pretty sure that is what I said too.

    oh well...
    Fusion Brain Version 6 Released!
    1.9in x 2.9in -- 47mm x 73mm
    30 Digital Outputs -- Directly drive a relay
    15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
    Buy now in the MP3Car.com Store

  2. #22
    FLAC
    Join Date
    May 2006
    Location
    Calgary, Alberta
    Posts
    1,718
    Quote Originally Posted by 2k1Toaster View Post
    Pretty sure that is what I said too.

    oh well...
    No, you said blah blah blah cigarette lighter, blah blah.......haha..........but ya, rereading your post now, I know what you mean. It was too confusing before!
    Ampie Case
    2.5" Hard Drive 80GB Samsung 5400RPM
    256 MB DDR2 PC5400
    Xenarc 700TSV - VGA Monitor
    Intel D945GCLF Motherboard
    M2-ATX-HV

    2005 Honda Civic

  3. #23
    FLAC
    Join Date
    May 2006
    Location
    Calgary, Alberta
    Posts
    1,718
    So now I have an issue. I have the slider being updated in the while loop where the file is being written (played). So when I drag the slider, it's hitting the change Listener which is then stopping the song and recalling the Player.playSong() method which then seeks to the correct part of the song and then starts playing. The problem is it's doing it too often, once I move the slider a little it tries to run the while loop like 1000 times to keep reading through through the song for every 1/1000 (it seems like) of movement in the slider. I need it to restart the song at the new position less often on slider movements. Like only if the slider is moved 1/100 of its value should it reposition the track. Or if I have to, maybe I could just have it keep playing until the slider is dropped and then have it restart the song at the new position.

    So in order to do the latter (still want to do the former if possible) then I would have to add the same change listener to the songSlider, but also add a mouseEvent to it which would pick up whether or not the slider's been clicked on. Then if songSlider.getValueIsAdjusting() is equal to true (slider being dragged) then it doesn't do anything. And when the mouseEvent picks up the mouseRelease, it calls player.playSong(String songLocation, int sliderPosition). But I think I have it all jumbled up the way I explained it......do I need the mouseEvent method? Is that the only way to get the mouseRelease? And maybe I don't need to check the getValueIsAdjusting(), I can just look for the mouseRelease.........my brain is mush right now......
    Ampie Case
    2.5" Hard Drive 80GB Samsung 5400RPM
    256 MB DDR2 PC5400
    Xenarc 700TSV - VGA Monitor
    Intel D945GCLF Motherboard
    M2-ATX-HV

    2005 Honda Civic

  4. #24
    Constant Bitrate coffeejolts's Avatar
    Join Date
    Jan 2006
    Location
    Duluth, GA
    Posts
    126
    Did you look at the gui code I gave you? JSlider already has what you need built in.

    if(!slider.getValueIsAdjusting(){
    //now set the song position
    }

  5. #25
    FLAC
    Join Date
    May 2006
    Location
    Calgary, Alberta
    Posts
    1,718
    Quote Originally Posted by coffeejolts View Post
    Did you look at the gui code I gave you? JSlider already has what you need built in.

    if(!slider.getValueIsAdjusting(){
    //now set the song position
    }
    I did but the issue is that it tries to set the song position as it's adjusting so once I grab it, it moves really slow because it's constantly trying to replay the song at every new position. So if I try to drag it 10 spots down the slider, it takes like 30 minutes.

    I also meant to ask if this could be solved by moving the songSlider update to the event dispatch thread like you suggested.
    Ampie Case
    2.5" Hard Drive 80GB Samsung 5400RPM
    256 MB DDR2 PC5400
    Xenarc 700TSV - VGA Monitor
    Intel D945GCLF Motherboard
    M2-ATX-HV

    2005 Honda Civic

  6. #26
    FLAC
    Join Date
    May 2006
    Location
    Calgary, Alberta
    Posts
    1,718
    OK, seems the getValueIsAdjusting() did work.....here's the 2 ways I did it.

    ChangeListener changeListener2 = new ChangeListener()
    {
    public void stateChanged(ChangeEvent e)
    {
    if (songSlider.getValueIsAdjusting())
    {
    new Thread(new Runnable()
    {
    public void run()
    {
    player.stopSong();
    player.playSong(currentSongLocation, songSlider.getValue());
    }
    }).start();
    }
    }
    };
    MouseAdapter sliderMouseAdapter = new MouseAdapter()
    {
    public void mouseReleased(MouseEvent ee)
    {
    new Thread(new Runnable()
    {
    public void run()
    {
    player.stopSong();
    player.playSong(currentSongLocation, songSlider.getValue());
    }
    }).start();
    }
    };
    The problem now is when I move the slider towards the end of the song, it could take 2-3 seconds for it to read up to that point. Any way around this?
    Ampie Case
    2.5" Hard Drive 80GB Samsung 5400RPM
    256 MB DDR2 PC5400
    Xenarc 700TSV - VGA Monitor
    Intel D945GCLF Motherboard
    M2-ATX-HV

    2005 Honda Civic

  7. #27
    Constant Bitrate coffeejolts's Avatar
    Join Date
    Jan 2006
    Location
    Duluth, GA
    Posts
    126
    Well, if you are checking whether the value is adjusting before you do anything, then that section of code is not your problem. I think this goes back to what I said earlier about threading and Swing.

    When you interact with a swing gui via the keyboard or mouse, those interactions occur on the event dispatch thread (EDT). It is important that all swing interactions and ONLY swing interactions are performed on the EDT. So, going back to that while loop you have updating the slider. That loop is not on the EDT. So you are modifying a swing component off of the EDT, which is bad practice. Then, you are setting the position of the song on the EDT, which is also bad practice. You need to get all the swing interactions on the EDT, and everything else off of the EDT.

    Swing programming is very difficult to do well, especially when you are beginning, because it requires you to have a very good understanding of multi threaded application design.

  8. #28
    FLAC
    Join Date
    May 2006
    Location
    Calgary, Alberta
    Posts
    1,718
    Thanks, looks like I'm going to have to sit down for a while and see if I can figure it out.
    Ampie Case
    2.5" Hard Drive 80GB Samsung 5400RPM
    256 MB DDR2 PC5400
    Xenarc 700TSV - VGA Monitor
    Intel D945GCLF Motherboard
    M2-ATX-HV

    2005 Honda Civic

  9. #29
    FLAC
    Join Date
    May 2006
    Location
    Calgary, Alberta
    Posts
    1,718
    I finally got a chance to read up on the multithreading. So from what I can gather, I should create a new class which runs on its own thread and updates the songSlider independent of anything else going on in the program. So would that mean I'd create a class called songSliderUpdater and then create a new object based on the class? Then run something like songSliderUpdater.update() in the while loop that reads/writes the song? And the update() method would have a Thread.sleep(500) line in it so it updates twice a second. Am I close? Or should I create a custom songSlider class that extends JSlider and then run something like songSlider.update()?
    Ampie Case
    2.5" Hard Drive 80GB Samsung 5400RPM
    256 MB DDR2 PC5400
    Xenarc 700TSV - VGA Monitor
    Intel D945GCLF Motherboard
    M2-ATX-HV

    2005 Honda Civic

  10. #30
    Constant Bitrate coffeejolts's Avatar
    Join Date
    Jan 2006
    Location
    Duluth, GA
    Posts
    126
    Well, you could do that- create a class that implements Runnable and start it in its own Thread. OR- you could use a javax.swing.Timer. Once you implement the ActionListener, all you have to do is call timer.start();

Page 3 of 7 FirstFirst 1234567 LastLast

Similar Threads

  1. EniCar the RR Clone
    By enitalp in forum Software & Software Development
    Replies: 296
    Last Post: 12-13-2008, 06:12 PM
  2. Why should I run a front end???
    By Slightly_Stoopi in forum General MP3Car Discussion
    Replies: 13
    Last Post: 06-28-2006, 03:32 PM
  3. This is an awesome front end, and here is why:
    By WhiteRabbit in forum NeoCar Media Center
    Replies: 47
    Last Post: 08-27-2005, 10:43 PM
  4. Web Based Front End
    By Zenith_Warrior in forum Software & Software Development
    Replies: 10
    Last Post: 07-02-2005, 07:03 PM
  5. Front end needed for semi commercial venture
    By Orange Bus in forum Software & Software Development
    Replies: 10
    Last Post: 04-28-2005, 02:59 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •