×

Discussion Board

Results 1 to 14 of 14

Hybrid View

  1. #1
    Registered User
    Join Date
    Jan 2014
    Posts
    31

    recordcontrol.setStream(output) throws NullPointerException

    I wrote this code and I get NullPointerException when using recordcontrol.setStream I understand that recordcontrol is null but i've checked this doc and it's exactly what they did, what am I doing wrong ? btw using JAVA ME SDK 3.4 and running this on emulator
    http://developer.nokia.com/Resources...rdControl.html
    Code:
    package audiosurf;
    
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    import javax.microedition.media.control.RecordControl;
    
    /**
     *
     * @author Roy
     */
    public class AudioAnalyzer implements Runnable{
        
        private Player audioPlayer;
        private RecordControl recordControl;
        private InputStream inputStream;
        private ByteArrayOutputStream recordOutput;
        private byte recordData [];
        private Thread thread;
        private boolean recordFinished;
        
        /**
         * Constructor.
         */
        public AudioAnalyzer()
        {
            try {
                thread = new Thread(this);
                recordFinished = false;
                //inputStream = getClass().getResourceAsStream("res/getlucky.mpg");
                //audioPlayer = Manager.createPlayer(inputStream, "audio/mpg");
                audioPlayer = Manager.createPlayer("http://puu.sh/35YTG.mp3");
                //audioPlayer = Manager.createPlayer("http://puu.sh/6n9jC.mp3");
                audioPlayer.realize();
                recordControl = (RecordControl)audioPlayer.getControl("RecordControl");
                if(recordControl == null){
                    System.out.println("not supported");
                }
                recordOutput = new ByteArrayOutputStream();
                recordControl.setRecordStream(recordOutput);
                recordControl.startRecord();
                audioPlayer.start();
                //thread.start();
            } catch (MediaException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        
        /**
         * 
         * @return the recordData; 
         */
        public byte [] getRecordData()
        {
            return recordData;
        }
        
        /**
         * 
         * @return the recordFinished; 
         */
        public boolean getRecordFinished()
        {
            return recordFinished;
        }
    
        /**
         * Checking when the player has finished playing the audio and copy the audio's recorded data into recordData.
         */
        public void run()
        {
            try {
                Thread.sleep(audioPlayer.getDuration() / 1000);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
            try {
                recordControl.commit();
                recordData = recordOutput.toByteArray();
                recordOutput.close();
                audioPlayer.close();
                recordFinished = true;
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        
    }

  2. #2
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    685

    Re: recordcontrol.setStream(output) throws NullPointerException

    RecordControl is not supported for the locator http:// that's why you get a NPE
    if you want to record something you should use the file:// locator and also note that the recording will be done with AMR format.
    Heard of DVLUP? Join here

  3. #3
    Registered User
    Join Date
    Jan 2014
    Posts
    31

    Re: recordcontrol.setStream(output) throws NullPointerException

    Quote Originally Posted by shai.i View Post
    RecordControl is not supported for the locator http:// that's why you get a NPE
    if you want to record something you should use the file:// locator and also note that the recording will be done with AMR format.
    hey shai thanks for letting me know this, but I'm not sure how to work with the file:// locater, this is what I did
    audioPlayer = Manager.createPlayer("file:///D:/getlucky.amr"); (btw the file has to be in amr format or you ment that the record will be converted to amr ?)
    and I get IO exception "java.io.IOException: Root is not accessible"

    I'm new to J2ME it'll be helpful if you could tell me what I did wrong

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: recordcontrol.setStream(output) throws NullPointerException

    d: is not necessarily an existing location. Consider checking FileSystemRegistry class and its listRoots method.

  5. #5
    Registered User
    Join Date
    Jan 2014
    Posts
    31

    Re: recordcontrol.setStream(output) throws NullPointerException

    Quote Originally Posted by wizard_hu_ View Post
    d: is not necessarily an existing location. Consider checking FileSystemRegistry class and its listRoots method.
    trying to print the list of roots just to see
    and Im getting i/o exception root is not accessible
    my main goal is to show on a list every audio file (songs) that are stored on the device how can I do that ?
    also while building my app im running it on sdk 3.4 from oracle emulator so I probably wont be able to test the app until later on real device so what can I do about it ? say I want to check the funcuallity of the method above (of obtaining all audios from device) on an emulator ? how can I do it since im testing on an emulator there're no audio files I can store on an actual device, hope you understand me, thanks in advance!

  6. #6
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    685

    Re: recordcontrol.setStream(output) throws NullPointerException

    You should never count on the root name being hardcode in your app code ("D:"),
    to obtain the list of roots available on the phone use
    FileSystemRegistry.listRoots();
    (note that some roots maybe read only and some writeable, you should check that via code)

    The file format will be AMR, also the file you are trying to write into you should create it first.

    If you target the new Asha devices (501,500,502,503) then you can use the build in File Dialog to allow the user to select a file, if not then you simply have to traverse the root and its inner directories to search for your desired media files , you can also try to use the System.property("fileconn.dir.tones") to get the path for the "tones" dir and perhaps use "fileconn.dir.memorycard" to get the memory card root if its available.

    The oracle and nokia emulators both have real paths in your pc to emulate the phone memory card so if you place a file there before you start your emulator it will be accessible from the emulator either via code or UI
    Heard of DVLUP? Join here

Similar Threads

  1. getProductData throws nullPointerException
    By preeti.s.patil in forum Monetization APIs
    Replies: 1
    Last Post: 2012-04-13, 09:02
  2. *Sometimes* getSnapshot throws MediaException, RecordControl Error
    By olan75 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2011-04-03, 16:11
  3. Using RecordStore.AUTHMODE_ANY throws NullPointerException
    By sgaber in forum Mobile Java General
    Replies: 10
    Last Post: 2007-12-18, 18:03
  4. recordcontrol.setStream(out) throws NullPointerException
    By bharatdevada in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2006-11-10, 01:16

Posting Permissions

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