Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7859855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:03:22+00:00 2026-06-02T22:03:22+00:00

My code is given below – I tried the documentation from the blackberry website.Its

  • 0

My code is given below – I tried the documentation from the blackberry website.Its not creating the audio file. How to solve this problem ?. Thanks in advance.

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import java.lang.*;

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.media.*;
import javax.microedition.media.Manager;

import java.io.*;
import javax.microedition.media.control.*;

public class AudioRecording extends UiApplication
{
public static void main(String[] args)
{
     AudioRecording app = new AudioRecording();
     app.enterEventDispatcher();
}

public AudioRecording()
{
     pushScreen(new AudioRecordingDemoScreen());
}

private class AudioRecordingDemoScreen extends MainScreen  
{   
    private AudioRecorderThread _recorderThread;
    ByteArrayOutputStream  bt;
    DataOutputStream  ot;
    public AudioRecordingDemoScreen()
    {
        //setTitle("Audio recording demo");

        addMenuItem(new StartRecording());
        addMenuItem(new StopRecording());
    }

    private class StartRecording extends MenuItem 
    {
        public StartRecording() 
        {
            super("Start recording", 0, 100);
        }

        public void run() 
        {
            try 
            {
                AudioRecorderThread newRecorderThread = new AudioRecorderThread();
                newRecorderThread.start();
                _recorderThread = newRecorderThread;
            }  
            catch (Exception e) 
            {
                Dialog.alert(e.toString());
            }
        }
    }

    private class StopRecording extends MenuItem 
    {
        public StopRecording() 
        {
            super("Stop recording", 0, 100);
        }

        public void run() 
        {
            try 
            {
                if (_recorderThread != null) 
                { 
                    _recorderThread.stop();
                }
            } 
            catch (Exception e) 
            {
                Dialog.alert(e.toString());
            }
        }
    }

    private class AudioRecorderThread extends Thread implements javax.microedition.media.PlayerListener
    {
        private Player _player;
        private RecordControl _recordControl;

        AudioRecorderThread()
        {
        }

        public void run() 
        {
            try 
            {
                _player = javax.microedition.media.Manager.createPlayer("capture://audio?encoding=amr");

                _player.addPlayerListener(this);

                _player.realize();
                _recordControl = (RecordControl) _player.getControl( "RecordControl" );

                FileConnection  fc = (FileConnection)Connector.open("file:///Device Memory/home/user/music/recordingFile.amr", Connector.READ_WRITE );
                if(!fc.exists()){
                    fc.create();
                }
                 ot = fc.openDataOutputStream();
                _recordControl.setRecordStream(ot);


                _recordControl.startRecord(); 
                _player.start();

            }
            catch( IOException e ) 
            {
                Dialog.alert(e.toString());
            }
            catch( MediaException e ) 
            {
                Dialog.alert(e.toString());
            }
        }
        public void stop() 
        {
        /*    if (_player != null) 
            {
                 _player.close();
                 _player = null;
            }

            if (_recordControl != null) 
            {
                _recordControl.stopRecord();*/

                try 
                {

                    _recordControl.commit();


                } 
                catch (Exception e) 
                {
                    Dialog.alert(e.toString());
                }
               /* _recordControl = null;
            } */



        }

        public void playerUpdate(Player player, String event, Object eventData) 
        {
            Dialog.alert("Player " + player.hashCode() + " got event " + event + ": " + eventData);
        }
    }
}
}

Its not creating file. How to solve this problem

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:03:26+00:00Added an answer on June 2, 2026 at 10:03 pm

    Try the following code –

    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.container.*;
    import net.rim.device.api.ui.component.*;
    import java.lang.*;
    
    import javax.microedition.io.Connector;
    import javax.microedition.io.file.FileConnection;
    import javax.microedition.media.*;
    import javax.microedition.media.Manager;
    
    import java.io.*;
    import javax.microedition.media.control.*;
    
    public class AudioRecording extends UiApplication
    {
    public static void main(String[] args)
    {
         AudioRecording app = new AudioRecording();
         app.enterEventDispatcher();
    }
    
    public AudioRecording()
    {
         pushScreen(new AudioRecordingDemoScreen());
    }
    
    private class AudioRecordingDemoScreen extends MainScreen  
    {   
        private AudioRecorderThread _recorderThread;
        ByteArrayOutputStream  bt;
        DataOutputStream  ot;
        public AudioRecordingDemoScreen()
        {
            //setTitle("Audio recording demo");
    
            addMenuItem(new StartRecording());
            addMenuItem(new StopRecording());
        }
    
        private class StartRecording extends MenuItem 
        {
            public StartRecording() 
            {
                super("Start recording", 0, 100);
            }
    
            public void run() 
            {
                try 
                {
                    AudioRecorderThread newRecorderThread = new AudioRecorderThread();
                    newRecorderThread.start();
                    _recorderThread = newRecorderThread;
                }  
                catch (Exception e) 
                {
                    Dialog.alert(e.toString());
                }
            }
        }
    
        private class StopRecording extends MenuItem 
        {
            public StopRecording() 
            {
                super("Stop recording", 0, 100);
            }
    
            public void run() 
            {
                try 
                {
                    if (_recorderThread != null) 
                    { 
                        _recorderThread.stop();
                    }
                } 
                catch (Exception e) 
                {
                    Dialog.alert(e.toString());
                }
            }
        }
    
        private class AudioRecorderThread extends Thread implements javax.microedition.media.PlayerListener
        {
             private Player _player;
               private RecordControl _rcontrol;
               private ByteArrayOutputStream _output;
               private byte _data[];
    
               AudioRecorderThread() {}
    
               private int getSize()
               {
                   return (_output != null ? _output.size() : 0);
               }
    
               private byte[] getVoiceNote()
               {
                  return _data;
               }
    
               public void run() {
                  try {
                      // Create a Player that captures live audio.
                      _player = Manager.createPlayer("capture://audio");
                      _player.realize();
    
                      // Get the RecordControl, set the record stream,
                      _rcontrol = (RecordControl)_player.getControl("RecordControl");
    
                      //Create a ByteArrayOutputStream to capture the audio stream.
                      _output = new ByteArrayOutputStream();
                      _rcontrol.setRecordStream(_output);
                      _rcontrol.startRecord();
                      _player.start();
    
                  } catch (final Exception e) {
                     UiApplication.getUiApplication().invokeAndWait(new Runnable() {
                        public void run() {
                           Dialog.inform(e.toString());
                        }
                     });
                  }
               }
    
               public void stop() {
                  try {
                       //Stop recording, capture data from the OutputStream,
                       //close the OutputStream and player.
                       _rcontrol.commit();
                       _data = _output.toByteArray();
    
                       saveRecordedFile(_data);
    
                       _output.close();
                       _player.close();
    
                  } catch (Exception e) {
                     synchronized (UiApplication.getEventLock()) {
                        Dialog.inform(e.toString());
                     }
                  }
               }
    
               public void playerUpdate(Player player, String event, Object eventData) 
               {
                   Dialog.alert("Player " + player.hashCode() + " got event " + event + ": " + eventData);
               }
            }
    }
    
    
    
    public static boolean saveRecordedFile(byte[] data) {
        try {
            String filePath1 = System.getProperty("fileconn.dir.music");
            String fileName = "sample";
            boolean existed = true;
            for (int i = 0; i < Integer.MAX_VALUE; i++) {
                try {
                    FileConnection fc = (FileConnection) Connector.open(filePath1 + fileName+ ".amr");
                    if (!fc.exists()) {
                        existed = false;
                    }
                    fc.close();
                } catch (IOException e) {
                    Dialog.alert("unable to save");
                    return existed;
                }
                if (!existed) {
                    fileName += i + ").amr";
                    filePath1 += fileName;
                    break;
                }
            }
            System.out.println(filePath1);
            System.out.println("");
            FileConnection fconn = (FileConnection) javax.microedition.io.Connector .open(filePath1, javax.microedition.io.Connector.READ_WRITE);
            if (fconn.exists())
                fconn.delete();
            fconn.create();
    
            OutputStream outputStream = fconn.openOutputStream();
            outputStream.write(data);
            outputStream.close();
            fconn.close();
            return true;
        } catch (Exception e) {
        }
        return false;
    }
    
    
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code given below generates an error. Conversion from string C:... to integer not
I tried the following code in LINQPad and got the results given below: List<string>
i understand that the code given below will not be compltely understood unless i
Are the JavaScript code snippets given below some sort of function declaration? If not
sample code given below is not compiled in g++. but it's working on visual
Code given below is taken from the stackoverflow.com !!! Can anyone tell me how
The code given below reads file contents to buffer, and then does something with
I had written the code given below: Its output datatype is integers, I want
In the code given below, I need to position the userid box in the
In the code given below, I am trying to modify it in such a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.