Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Problem with java media framework

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    26
    My Mood
    Aggressive
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Problem with java media framework

    This is my code that plays the audio files:

    /**
     * Author: audioPlayer
     * Project: DesktopApp
     */
     
    package appClass;
     
    import java.io.File;
    import java.io.IOException;
    import javax.media.*;
    import javax.media.format.AudioFormat;
     
    public class audioPlayer {
     
        private Player[] player;
        private Format in1;
        private Format in2;
        private Format out;
        private int filePlaying;
     
        public audioPlayer(){
     
        }
     
        public void loadAudio(File[] file){
            in1 = new AudioFormat(AudioFormat.MPEGLAYER3);
            in2 = new AudioFormat(AudioFormat.MPEG);
            out = new AudioFormat(AudioFormat.LINEAR);
            PlugInManager.addPlugIn(
                    "com.sun.media.codec.audio.mp3.JavaDecoder",
                    new Format[]{in1, in2},
                    new Format[]{out},
                    PlugInManager.CODEC
            );
            try{
     
                for(int i = 0; i<file.length; i++){
                    MediaLocator mL = new MediaLocator(file[i].toURI().toURL()); 
                    System.out.print(file[i].toURI().toURL());
     
                    //ERROR POINTS HERE
                    player[i]= Manager.createPlayer(mL);                
     
     
                }
            }
            catch(IOException | NoPlayerException e){
                e.printStackTrace();
            }
        }
     
        public void playSound(int fileCount){
                player[fileCount].start();
                filePlaying = fileCount;
        }
     
        public void stopSound(){
            if(player[filePlaying]!=null){
                player[filePlaying].stop();
            }
        }
     
    }

    and that was called by this:

    aP.loadAudio(mM.getFiles());

    mM is a class that gets all the audioFiles from a certain directory

    here:

     
        private String path = System.getProperty("user.home")+"\\Music";
     
        private File[] file;
     
        public File[] getFiles(){
            return file;
        }
     
        public String getPath(){
            return path;
        }
     
        private FileFilter audioFiles = new FileFilter(){
     
            @Override
            public boolean accept(File file) {
                return file.getName().endsWith(".mp3") || file.getName().endsWith(".MP3") || file.getName().endsWith(".WAV") || file.getName().endsWith(".wav");
            }
     
        };
     
        public void loadFiles(){        
            File folder = new File(path);
            file = folder.listFiles(audioFiles);
        }

    but it keeps saying that my file is a null but when i printed whats the name of the file, it is not null it has name like a real mp3 file...

    jmf.jpg

    My Goal:

    I want to array the Player because when it is not arrayed, and when i try to play a file, it loads the file first before playing it and it takes 1-3 seconds which is not good. I tried to do this hoping it wouldn't load and when i try to play another file it plays instantly.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problem with java media framework

    it keeps saying that my file is a null
    Please copy the full text of the error message and post it here.

    What variable has the null value? Backtrack in the code to see why that variable does not have a valid value.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    26
    My Mood
    Aggressive
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Problem with java media framework

    MediaLocator mL = new MediaLocator(file[i].toURI().toURL()); 
    System.out.print(file[i].toURI().toURL());
     
    //ERROR POINTS HERE
    player[i]= Manager.createPlayer(mL);
    full code is on the top


    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at appClass.audioPlayer.loadAudio(audioPlayer.java:41)
    	at gui.wallpaperPanel.btnMyMusicActionPerformed(wallpaperPanel.java:426)
    	at gui.wallpaperPanel.access$300(wallpaperPanel.java:18)
    	at gui.wallpaperPanel$4.actionPerformed(wallpaperPanel.java:196)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    	at java.awt.Component.processMouseEvent(Component.java:6505)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    	at java.awt.Component.processEvent(Component.java:6270)
    	at java.awt.Container.processEvent(Container.java:2229)
    	at java.awt.Component.dispatchEventImpl(Component.java:4861)
    	at java.awt.Container.dispatchEventImpl(Container.java:2287)
    	at java.awt.Component.dispatchEvent(Component.java:4687)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    	at java.awt.Container.dispatchEventImpl(Container.java:2273)
    	at java.awt.Window.dispatchEventImpl(Window.java:2719)
    	at java.awt.Component.dispatchEvent(Component.java:4687)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
    	at java.awt.EventQueue.access$200(EventQueue.java:103)
    	at java.awt.EventQueue$3.run(EventQueue.java:688)
    	at java.awt.EventQueue$3.run(EventQueue.java:686)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    	at java.awt.EventQueue$4.run(EventQueue.java:702)
    	at java.awt.EventQueue$4.run(EventQueue.java:700)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
    BUILD SUCCESSFUL (total time: 6 seconds)

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problem with java media framework

    What variable has the null value? Why doesn't that variable have a valid value?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    26
    My Mood
    Aggressive
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Problem with java media framework

    i think the null value is the MediaLocator saying i cant see the file, but i printed the value of the file, it has. I dont know why it was invalid, i was doing it a while ago (no arrays on Players) and it was doing right.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problem with java media framework

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at appClass.audioPlayer.loadAudio(audioPlayer.java:41 )
    Print the values of all the variables used on line 41 to see which one has the null value.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2013
    Posts
    26
    My Mood
    Aggressive
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Problem with java media framework

    Quote Originally Posted by Norm View Post
    Print the values of all the variables used on line 41 to see which one has the null value.
    please look at my attachment, it was been there since this thread was started, and if you dont want to, it has value and it contradicts to the output saying it is null

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problem with java media framework

    What was printed out when you added a println() statement to print out the values of the variables used on line 41? Which variable on that line has a null value? To solve this kind of error you need to find what variable is null and change the code so it has a valid value.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Restlet framework in java
    By gaurav_tata in forum Java Networking
    Replies: 1
    Last Post: January 28th, 2013, 11:04 AM
  2. what is Java assertion framework?
    By cloud9resident in forum Java Theory & Questions
    Replies: 1
    Last Post: December 10th, 2012, 10:07 AM
  3. Replies: 0
    Last Post: November 11th, 2012, 09:53 PM
  4. Media Player Help in java
    By Tajinder in forum Java SE APIs
    Replies: 2
    Last Post: September 27th, 2011, 12:00 PM
  5. [SOLVED] Best Java web framework
    By renu1 in forum Web Frameworks
    Replies: 1
    Last Post: March 15th, 2010, 09:16 AM