Page 4 of 7 FirstFirst 1234567 LastLast
Results 31 to 40 of 62

Thread: Building A Completely Java Based Front End

  1. #31
    FLAC
    Join Date
    May 2006
    Location
    Calgary, Alberta
    Posts
    1,718
    Quote Originally Posted by coffeejolts View Post
    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();
    Interesting........so I guess that would simply mean to have a songSlider.setvalue() call inside the timer? And tie the action listener to the play/double click. This helps me understand a lot, thanks (unless I'm wrong). I'll see what I can put together tomorrow to test. I might be the first person to post working code here for a working song slider.
    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

  2. #32
    Constant Bitrate coffeejolts's Avatar
    Join Date
    Jan 2006
    Location
    Duluth, GA
    Posts
    126

    Talking

    Quote Originally Posted by Maheriano View Post
    Interesting........so I guess that would simply mean to have a songSlider.setvalue() call inside the timer? And tie the action listener to the play/double click. This helps me understand a lot, thanks (unless I'm wrong). I'll see what I can put together tomorrow to test. I might be the first person to post working code here for a working song slider.
    You might be the first to post it, but not the first to do it.

    Anyhow, the ActionListener in the timer will be called by the timer tick events, ie- every n milliseconds until timer.stop() is called. ActionListeners are notified on the EDT, so you can be sure that you are updating the slider position on the correct thread. So, you'll want to start the timer when the song begins to play, and stop the timer when you stop the song. You may want to stop it when you drag the slider as well, but I'm not sure if that is necessary (it's been a while).

  3. #33
    FLAC
    Join Date
    May 2006
    Location
    Calgary, Alberta
    Posts
    1,718
    You, sir, are a genius.

    Here's my new Player try block:
    try
    {
    File file = new File(songLocation);
    fileSize = file.length();
    in = AudioSystem.getAudioInputStream(file);
    AudioFormat baseFormat = in.getFormat();
    AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
    din = AudioSystem.getAudioInputStream(decodedFormat, in);
    DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat);
    line = (SourceDataLine) AudioSystem.getLine(info);
    if (line != null)
    {
    line.open(decodedFormat);
    data = new byte[4096];
    // Start
    line.start();
    while ((nBytesRead = din.read(data, 0, data.length)) != -1)
    {
    numberOfBytesRead = fileSize - in.available();
    if (numberOfBytesRead > currentPosition)
    {
    line.write(data, 0, nBytesRead);
    }
    }
    // Stop
    /* line.drain();
    line.stop();
    line.close();
    din.close();*/
    }
    }
    Here's Player.getSliderPosition():
    public long getSliderPosition()
    {
    return numberOfBytesRead * 1000 / fileSize;
    }
    And the Timer:
    final Timer timer = new Timer(1000, new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    songSlider.setValue((int)player.getSliderPosition( ));
    }
    });
    And the GUI:
    if (event.getSource() == playButton)
    {
    final MusicFile mf = (MusicFile)list.getSelectedValue();
    final String location = mf.getPath();
    currentSongLocation = location;
    // albumCover.setIcon(new ImageIcon(mf.getCanonicalPath() + "\\cover.jpg"));

    try
    {
    BufferedImage buffImg = ImageIO.read(new File(mf.getCanonicalPath() + "\\cover.jpg"));
    Image image = buffImg.getScaledInstance(200,200,Image.SCALE_SMOO TH);
    albumCover.setIcon(new ImageIcon(image));
    }
    catch (IOException e2)
    {
    e2.printStackTrace();
    }

    new Thread(new Runnable()
    {
    public void run()
    {
    songLabel.setText(mf.getName());
    player.stopSong();
    player.playSong(currentSongLocation, songSlider.getValue());
    }
    }).start();

    timer.start();
    }
    I still have some issues with moving the slider around a lot and there's still a lag if I move it far ahead but I'll be looking into it a little further this afternoon. Thanks for your help and let me know if I've done it right!
    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. #34
    FLAC
    Join Date
    May 2006
    Location
    Calgary, Alberta
    Posts
    1,718
    My goal is to get it working and into my car. And maybe over the next few years to polish it into exactly what people want. Then eventually somehow use it to generate revenue.

    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

  5. #35
    Constant Bitrate
    Join Date
    Oct 2007
    Posts
    219
    the only thing I could recommend is to make all sizes and coordinates percentage values. Define your screen as measuring 1 unit, then you define all sizes and coordinates as a fraction of 1.

    Code:
    0 --------- .5 ------------ 1 (0,1)
    | (0,0)  |  
    |        |
    |        |                          
    |------(.3,.3)                           
    |                                      
    .5                                    
    |                                      
    |                                      
    |                                      
    1---------- .5 ------------ 1 (1,1)
    then the real sizes and coordinates would be the fraction X real size

    This will let you resize your screen to any size and it will look good

  6. #36
    Constant Bitrate coffeejolts's Avatar
    Join Date
    Jan 2006
    Location
    Duluth, GA
    Posts
    126
    ^^^wtf?
    Java has something called layout managers that handle these things.

  7. #37
    Constant Bitrate
    Join Date
    Oct 2007
    Posts
    219
    Quote Originally Posted by coffeejolts View Post
    ^^^wtf?
    Java has something called layout managers that handle these things.
    Yes, layout managers are good to keep, well, a layout.
    You would still want to define sizes and coordinates as percentages. What good is to have a big 4x4 grid with a very small button inside each cell. Make the button size and position relative to the panel size. That way, the bigger the screen, the bigger the content.

    BTW, TRWTF is how C#,vb.net doesn't have integrated layout managers



    [no quack]

  8. #38
    Constant Bitrate coffeejolts's Avatar
    Join Date
    Jan 2006
    Location
    Duluth, GA
    Posts
    126
    Quote Originally Posted by silvi4000
    What good is to have a big 4x4 grid with a very small button inside each cell.
    Check out gridlayout- it does exactly what you describe. Lay out a grid of buttons and they grow or shrink with the container.

  9. #39
    Constant Bitrate
    Join Date
    Oct 2007
    Posts
    219
    Quote Originally Posted by coffeejolts View Post
    Check out gridlayout- it does exactly what you describe. Lay out a grid of buttons and they grow or shrink with the container.
    yes, layout managers are a must. Im just referring to the actual content inside the layout.
    Take for example having some text. I might want to make the text relative to the screen size. If I define the text size as a percentage of the total size, I can resize the screen to any size and the aspect ratio will be maintained.

    Its not a big deal, I just hate web pages that only use a fixed size of my 1920x1200 screen, and winforms that cant be resized, and winforms that break when using large DPIs ...... (im old)

  10. #40
    Constant Bitrate coffeejolts's Avatar
    Join Date
    Jan 2006
    Location
    Duluth, GA
    Posts
    126
    ok

Page 4 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, 05: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, 02: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, 09:43 PM
  4. Web Based Front End
    By Zenith_Warrior in forum Software & Software Development
    Replies: 10
    Last Post: 07-02-2005, 06: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, 01: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
  •