Page 2 of 7 FirstFirst 1234567 LastLast
Results 11 to 20 of 62

Thread: Building A Completely Java Based Front End

  1. #11
    It ain't easy being a green moderator meddler's Avatar
    Join Date
    Aug 2002
    Location
    Steps out the front of Henson's workshop or Sydney
    Posts
    2,783
    I always keep an eye on frontends. It is always good to see what is being developed.
    Never let the truth get in the way of a good story

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

    Challenges

    How much time have you spent researching the challenges involved in making a truly great Java front-end? By 'great', I mean that people would prefer your app over what is currently on the market, regardless of price.

    I've been building simple test cases for a while now, and I have yet to find a cost effective solution to the following...

    1. DRM infected music. There are a lot of people with subscriptions to music services. These people will naturally expect their music to play on their carpc. How would you play subscription-downloaded music in a cross platform manner? Sure, you could always write a wrapper around WMP (or buy one), but then you kill the cross platform compatability.

    2. Navigation. You can use Java to access the GPS receiver, but then you have the challenge of how to display it. You could use one of the online map providers, but that would require users to be always connected to the internet. Again, you could write a wrapper around mappoint or some other sdk, but you kill the cross platform part. I've searched and searched for a Java solution, but came up empty every time.

    These are the hard challenges. If you can think of a way around them, I'd be happy to help you out.

    @The Java-haters above: java itself is not slow, the recent jres (1.5+) have great performance. Cold startup time is admittedly an issue. However, once the jre starts, you would be hard pressed to see the performance difference.

  3. #13
    FLAC
    Join Date
    May 2006
    Location
    Calgary, Alberta
    Posts
    1,718
    1. WTF is DRM?
    2. For navigation I would just embed iGuidance again, I'm not looking for something cross platform, this is simply a front end for me specifically. And if anyone else likes it then they can use it too!

    But I'm kind of stuck right now as to how I skip to a specified portion of the audio file after moving the slider. I can't figure that out. I don't see any methods that take a byte/frame position in the file as a parameter to use as a starting point.
    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. #14
    Constant Bitrate coffeejolts's Avatar
    Join Date
    Jan 2006
    Location
    Duluth, GA
    Posts
    126
    1. DRM = Digital Rights Management, aka restricted files. This is put on files that you download from music subscription services (Napster, iTunes, etc...)

    2. It seems odd to use Java to write a platform specific application. If I was going to write for windows only, I'd just use C# or VB, which allow much tighter integration into the underlying platform. I know you only know Java right now, but this may be a good excuse for you to learn C# (very Java-like). It looks good on a resume to know more than one language anyhow.

    3. If you were able to pull off a great, fully cross platform frontend in Java, you'd be a star at the next JavaOne.

    4. What method are you using to play music files? Maybe I can help you on the seek functionality.

  5. #15
    FLAC
    Join Date
    May 2006
    Location
    Calgary, Alberta
    Posts
    1,718
    Quote Originally Posted by coffeejolts View Post
    1. DRM = Digital Rights Management, aka restricted files. This is put on files that you download from music subscription services (Napster, iTunes, etc...)

    2. It seems odd to use Java to write a platform specific application. If I was going to write for windows only, I'd just use C# or VB, which allow much tighter integration into the underlying platform. I know you only know Java right now, but this may be a good excuse for you to learn C# (very Java-like). It looks good on a resume to know more than one language anyhow.

    3. If you were able to pull off a great, fully cross platform frontend in Java, you'd be a star at the next JavaOne.

    4. What method are you using to play music files? Maybe I can help you on the seek functionality.
    DRM......right, but I don't understand what the issue is. Just put it in your car and play it........it doesn't work? Why would anyone buy a song you can't port?

    I'm using the Java Media Framework (JMF) to play the songs right now, I wrote my own player for it by creating an AudioInputStream and reading from the file, then writing to the stream. I've posted it a few times on the Java forums at Sun but no luck, not even any replies. Here's the Player class I wrote:
    import java.io.File;
    import java.io.IOException;

    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.BooleanControl;
    import javax.sound.sampled.Control;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.FloatControl;
    import javax.sound.sampled.SourceDataLine;
    import javax.sound.sampled.FloatControl.Type;
    import javax.swing.SwingUtilities;


    public class Player
    {


    public Player()
    {

    }

    public void playSong(String song)
    {
    final String songLocation = song;
    {
    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();
    long percentageOfFileRead;
    long numberOfBytesRead;
    while ((nBytesRead = din.read(data, 0, data.length)) != -1)
    {
    line.write(data, 0, nBytesRead);
    System.out.println("Frame length = " + din.getFrameLength());
    numberOfBytesRead = fileSize - in.available();
    percentageOfFileRead = (numberOfBytesRead * 100) / fileSize;
    MusicGUI.songSlider.setValue((int)percentageOfFile Read);
    }
    // Stop
    /* line.drain();
    line.stop();
    line.close();
    din.close();*/
    }
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    finally
    {
    if(din != null)
    {
    try
    {
    din.close();
    }
    catch(IOException e)
    {
    System.out.println("Error: " + e);
    }
    }
    }
    }
    try
    {
    Thread.sleep(800);
    }
    catch (InterruptedException e)
    {
    e.printStackTrace();
    }
    }

    public void stopSong()
    {
    if(din != null)
    {
    try
    {
    line.stop();
    line.close();
    din.close();
    }
    catch(IOException e)
    {
    System.out.println("Error: " + e);
    }
    }
    }


    public void muteLine()
    {
    /* control = (BooleanControl)line.getControl(BooleanControl.Typ e.MUTE);
    if (control.getValue() == true)
    {
    control.setValue(false);
    }
    else
    {
    control.setValue(true);
    }
    */
    volumeControl = (FloatControl)line.getControl(FloatControl.Type.MA STER_GAIN);
    if (volumeControl.getValue() == -80)
    {
    volumeControl.shift(-80, 6, 400000000);
    }
    else
    {
    volumeControl.setValue(-80);
    }
    }

    public int getElapsedTime()
    {
    return nBytesRead;
    }

    public void setElapsedTime(int newPosition)
    {
    if(newPosition > 0)
    {
    temp = (int)fileSize * newPosition / 100;
    System.out.println("File Size = " + fileSize);
    System.out.println("Slider Position = " + newPosition);
    System.out.println("Number of bytes to skip to = " + temp);
    try
    {
    din.skip(500);
    }
    catch(IOException e)
    {
    e.printStackTrace();
    }
    }
    }

    public String getVolume()
    {
    volumeControl = (FloatControl)line.getControl(FloatControl.Type.MA STER_GAIN);
    return volumeControl.toString();
    }

    public void setVolume(int volume)
    {
    volumeControl = (FloatControl)line.getControl(FloatControl.Type.MA STER_GAIN);
    volumeControl.setValue(volumeControl.getValue() + (float).1);
    }

    private long i = 0;
    private int temp;
    private long fileSize;
    private byte[] data;
    private int nBytesRead;
    private SourceDataLine line = null;
    private FloatControl volumeControl = null;
    BooleanControl control = null;
    AudioInputStream in = null;
    AudioInputStream din = null;
    }
    Forget the getter / setter methods at the bottom, the place it's playing the song is this line:
    while ((nBytesRead = din.read(data, 0, data.length)) != -1)
    {
    line.write(data, 0, nBytesRead);
    }
    It's buffering 4096 bytes, writing (playing) it, then getting the next 4096 bytes and it does that for the whole song. It works perfect and the slider follows along with it but when I move the slider I can't get the song to jump, I'm lost at how to do this. Let me know if you want any more code. Thanks!
    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. #16
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    % of slider bar = (slider value)/(total possible slider value)

    get to byte area = ((total stream length) * (% of slider bar))/4096

    for int i = 0, i < (get to byte area); i++) {skip ahead in stream but dont play}
    play stream from current stream position



    Also, the only reason to make a java frontend, is for cross-OS support. Dont take offense, but you wont be able to create a frontend in java to rival RoadRunner and StreetDeck on features, support, or options. Your only saving grace is cross-OS support which could be a catchy item.

    So if you are going to do it, do it right, or not at all.
    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

  7. #17
    Constant Bitrate coffeejolts's Avatar
    Join Date
    Jan 2006
    Location
    Duluth, GA
    Posts
    126
    I looked over your code real fast. You don't include the GUI code, but I assume you're using a JSlider from the code you gave.

    You'll need to add a state change listener to the JSlider in order to get slide events from it. So, you'll do something like this in the code that initializes the slider

    Code:
    songSlider.addChangeListener(new javax.swing.event.ChangeListener() {
                public void stateChanged(javax.swing.event.ChangeEvent evt) {
                    songSliderStateChanged(evt);
                }
            });
    
    //and you'll need to implement songSliderStateChanged like this...
    
    private void songSliderStateChanged(javax.swing.event.ChangeEvent evt){
         if(!songSlider.getValueIsAdjusting()){
              double percent = songSlider.getValue() / 100.00;
              //now set the position of the song using this percentage
         }
    }
    Some advice, I'm trying to help....

    NEVER modify swing components on any thread other than the event dispatch thread. If you don't understand what I'm talking about, Google it. The while loop you use to update the slider is begging for trouble. Seriously. Job #1 for a Swing developer is to understand the event dispatch thread and what should and should not be performed on it.

  8. #18
    FLAC
    Join Date
    May 2006
    Location
    Calgary, Alberta
    Posts
    1,718
    Hmmmm..........good idea, I'll look into the thread issues, thanks. But I've already got a change listener and I'm getting the exact slide percentage and passing it back to the player and getting the exact byte placement in the file I need to start at. It's the starting the audio file from somewhere other than the beginning that is troubling me. I don't see any classes/methods that allow this. Any ideas?
    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. #19
    Constant Bitrate coffeejolts's Avatar
    Join Date
    Jan 2006
    Location
    Duluth, GA
    Posts
    126
    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(...)

  10. #20
    FLAC
    Join Date
    May 2006
    Location
    Calgary, Alberta
    Posts
    1,718
    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(...)
    That worked on a test run, you're a smart guy! So tell me if I have anything wrong with my plan of attack:
    - The current playSong() method takes the song location as a parameter. I should add the slider position as another parameter to this.
    - Call playSong(String, int) when a song is chosen.
    - Have song read to slider position percentage and then start playing file.
    - Move slider, activate change listener, call playSong inside change listener.
    - playSong is called again every time the slider is moved, once again starting the song at the passed slider position.
    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

Page 2 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
  •