Exception during Audio recording
Hello
I am trying to create a screen where the user can start and the voice to stop recording.
Start button will start the recording of the voice, where as stop stop recording and store the voice record.
I looked for Ko Javadevelopment and found some code and changed according to my understanding (as the code is available in pieces).
When I press the Start Recording button, I get an exception "java.lang.ClassCastException.
Can you please help me to solve the same.
I'm pasting my entire code here for your reference.
package comp; import java.io.IOException; import net.rim.device.api.ui.Field; import net.rim.device.api.ui.FieldChangeListener; import net.rim.device.api.ui.component.ButtonField; import net.rim.device.api.ui.component.LabelField; import net.rim.device.api.ui.container.HorizontalFieldManager; import net.rim.device.api.ui.container.MainScreen; public class myAudio extends MainScreen { private ButtonField _startRecordingButton; private ButtonField _stopRecordingButton; private HorizontalFieldManager _fieldManagerButtons; private VoiceNotesRecorderThread _voiceRecorder; private LabelField _myAudioTextField; public myAudio() { _startRecordingButton = new ButtonField("Start Recording"); _stopRecordingButton = new ButtonField("Stop Recording"); _fieldManagerButtons = new HorizontalFieldManager(); _voiceRecorder = new VoiceNotesRecorderThread(5000,"file:///store/home/user/myfile.amr",this); _voiceRecorder.start(); myButtonFieldChangeListener buttonFieldChangeListener = new myButtonFieldChangeListener(); _startRecordingButton.setChangeListener(buttonFieldChangeListener); _stopRecordingButton.setChangeListener(buttonFieldChangeListener); _fieldManagerButtons.add(_startRecordingButton); _fieldManagerButtons.add(_stopRecordingButton); _myAudioTextField = new LabelField(" Hello..." ); add(_fieldManagerButtons); add(_myAudioTextField); } public void setAudioTextField(String text) { _myAudioTextField.setText(text); } class myButtonFieldChangeListener implements FieldChangeListener{ public void fieldChanged(Field field, int context) { if(field == _startRecordingButton) { try { _voiceRecorder.startRecording(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }else if(field == _stopRecordingButton) { _voiceRecorder.stopRecording(); } } } } package comp; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import javax.microedition.io.Connector; import javax.microedition.io.file.FileConnection; import javax.microedition.media.Manager; import javax.microedition.media.Player; import javax.microedition.media.control.RecordControl; import net.rim.device.api.ui.Field; import net.rim.device.api.ui.FieldChangeListener; import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.component.Dialog; import net.rim.device.api.ui.container.MainScreen; public class VoiceNotesRecorderThread extends Thread { private Player _player; private RecordControl _rcontrol; private ByteArrayOutputStream _output; private byte _data[]; private int recordSizeLimit; private String recordFileName; private myAudio myAudioScreen; private FileConnection fileConn; VoiceNotesRecorderThread(int limit, String filePath, myAudio screen) { fileConn = null; recordSizeLimit = limit; recordFileName = filePath; myAudioScreen = screen; } private int getSize() { return (_output != null ? _output.size() : 0); } private byte[] getVoiceNote() { return _data; } // public void run() { // while(true){ // synchronized (UiApplication.getEventLock()) { // myAudioScreen.setAudioTextField(" Running Thread..."); // } // } // } public boolean startRecording() throws IOException { _output = null; _rcontrol = null; _player = null; try { synchronized (UiApplication.getEventLock()) { myAudioScreen.setAudioTextField(" Start Recording..."); } fileConn = (FileConnection) Connector.open(recordFileName); if (fileConn.exists()) { fileConn.delete(); synchronized (UiApplication.getEventLock()) { Dialog.inform(" File: File is already available" ); } } fileConn.close(); fileConn = (FileConnection) Connector.open(recordFileName, Connector.WRITE ); fileConn.create(); _output = (ByteArrayOutputStream) fileConn.openOutputStream(); //Create a ByteArrayOutputStream to capture the audio stream. //_output = new ByteArrayOutputStream(); // Create a Player that captures live audio. _player = Manager.createPlayer("capture:///audio?encoding=audio/amr"); _player.realize(); synchronized (UiApplication.getEventLock()) { Dialog.inform(" Player is Created" ); } // Get the RecordControl, set the record stream, _rcontrol = (RecordControl)_player.getControl("RecordControl"); _rcontrol.setRecordSizeLimit(recordSizeLimit); //_rcontrol.setRecordLocation(pathToRecording); _rcontrol.setRecordStream(_output); _rcontrol.startRecord(); _player.start(); synchronized (UiApplication.getEventLock()) { Dialog.inform(" Player is Started" ); } //_output.reset(); //_player.addPlayerListener(playerListen); } catch ( Exception e) { if(fileConn != null) { fileConn.delete(); fileConn.close(); } synchronized (UiApplication.getEventLock()) { Dialog.inform(" StartRecording: Exception "+ e.toString() ); } return false; } return true; } public void stopRecording() { try { synchronized (UiApplication.getEventLock()) { myAudioScreen.setAudioTextField(" Stop Recording..."); } if(_rcontrol != null) { _rcontrol.commit(); } else { synchronized (UiApplication.getEventLock()) { Dialog.inform(" _rcontrol is null " ); } } if(_output != null) { //_output.flush(); if(!(_output.size() >0) ) { synchronized (UiApplication.getEventLock()) { Dialog.inform(" _output buffer empty " ); } } _data = _output.toByteArray(); _output.close(); } if(!(_data.length > 0)) { synchronized (UiApplication.getEventLock()) { Dialog.inform(" Data gone baby gone " ); } } if(_player != null) { _player.close(); _player = null; } } catch (final Exception e) { synchronized (UiApplication.getEventLock()) { Dialog.inform(" Stop recording Failed: " + e.toString()); } return; //Dialog.inform(e.toString()); } } class FieldListener implements FieldChangeListener { Object recordButtonField = null; Object stopRecordingButtonField = null; public void fieldChanged(Field field, int context) { if(field.equals(recordButtonField)) { try { startRecording(); } catch (IOException e) { synchronized (UiApplication.getEventLock()) { Dialog.inform(" Start Button Exception: " + e.toString()); } //e.printStackTrace(); } /*recording only occurs during the sleep*/ } else if(field.equals(stopRecordingButtonField)) { stopRecording(); } } } }
_player = Manager.createPlayer ("capture://audio?encoding=audio/amr");
Mark as resolved
Give us some kudoes
Tags: BlackBerry Developers
Similar Questions
-
Microphone is not record audio (my voice) during the recording of videos!
So, today I went to check on some of my video files to modify and at their reading, I heard no noise. I was confused by this because in the past, my microphone was fine and should record audio without a problem. But all of a sudden it stopped working at all, at least for the record there. When I'm in Skype calls, my microphone seems to work because I can be heard. But when I try and save, my microphone is not working. I record with Fraps and tried a lot of different options within the system itself. I tried "His file Win7" stereo and surround, and two of them did not work. I even went to Skype call testing service to see if my microphone still worked, and when it reproduces the audio I could hear myself using the microphone. Please help me because I don't know what the problem is!
Edit: Forgot to say that I tried to record with no microphone but the eternal mic and I have all his be picked up when recording, but when I tested it with Skype, I could hear audio.
Re Edit: So I tried later and tested with my microphone and could not hear any audio, but when I used the computer's microphone, I could hear audio! So that leads me to believe that my mic is broken, but I can't be sure.
Hello
First I want to apologize for the delay in responding.
Here, in this scenario, this could be a problem with the hardware or driver issues. I would suggest trying the following methods and check if it helps.
Method 1:
Run the troubleshooter audio recording and check if the problem persists. See the following article to run the troubleshooter in Microsoft Help.
http://Windows.Microsoft.com/en-us/Windows7/open-the-recording-audio-Troubleshooter
Method 2:
Try to install the latest audio drivers, including drivers for the chipset and check if it works for you.
See the following Microsoft Help article to update the drivers for hardware that does not work correctly.
http://Windows.Microsoft.com/en-us/Windows/Update-driver-hardware-ISN
If the problem persists, then it would be best to contact the manufacturer of equipment computer for more help on this issue.
Please reply with the status of the issue so that we can better help you.
-
Hi all
Can anyone suggest me the code to run the audio recording!
The implementation of audio recording!
Hello
Check this code it will work.
try{ player = Manager.createPlayer("capture://audio?encoding=amr"); player.realize(); rc = (RecordControl)player.getControl("RecordControl"); bt = new ByteArrayOutputStream(); rc.setRecordStream(bt); fc = (FileConnection)Connector.open("file:///store/home/user/RecordedFiles/audio1.amr"); if(!fc.exists()){ fc.create(); } ot = fc.openDataOutputStream(); rc.setRecordStream(ot); rc.startRecord(); player.start(); }catch(Exception e){ e.printStackTrace(); }
-
How to limit the audio recording time?
Hello
I want to limit the audio recording time 60 seconds. How can this be achieved? I've seen a single method but its to set the size. Or is it possible to get new coding time during recording? Please help me!
When you start recording start timer once it reaches 60secs... stop recording.
-
Audio recording in voice command (no transcript of speech recognition)
Does anyone know a program/application record that allows a person control the audio audio functions during an audio recording with voice commands? I would like to dictate (no transcript required) to a .wav file or .dss with an earpiece bluetooth and power say 'start', 'stop', 'rewind', etc. when recording while I'm totally hands-free during the autospies I do.
Hello
I would say that you can use your favorite search engine to download and install a voice controlled application audio recording, you need to use.
NOTE: Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.
Hope this information is useful.
-
a fusion drive is good for audio recording?
I think buy a 27-inch iMac for audio recording on Logic Pro X, but is not sure a merger player performance, because some say that the part of the HARD of it on only 5400 RPM drive, if I hold with an iMac HARD 7200 RPM drive?
You will likely get different opinions, but personally I would not use the fusion drive and recommend an SSD.
Quite significant speed difference.
-
Siri and audio recording does not
Hello
the audio recording with my front camera does not work and Siri cannot hear what I say.
All the other stuff that needs a microphone works perfectly and I installed the latest version of IOS
Hope someone has an answer to this problem
Vanessa
Hello
Try following the steps outlined here:
- Siri to use on your iPhone, iPad or iPod touch - Apple Support (see 'Get help').
-
The logic using Soundflower audio recording system
Let's start with the agreement that I must be a fool.
I found tutorials on the net for logic audio recording using sound flower and it seems very simple.
I actually have to make what I want sometimes.
For the life of me I can't recreate my past successes.
I'm to the point of madness here.
I want to just record from Chrome, etc... any audio system, the logic.
Help, please
Drew
1 / set your output to the system on your Mac for soundflower.
(so now if you play a youtube video or a song on iTunes you won't hear anything - as it is realized in SF).
2. in line with defined preferences of-> audio-> entry to soundflower
and something other than control panel the value out of logic (built in output is fine)
3 / create an audio track and assign to its entrance at Gate 1
4 / record select the track or you can monitor the track entrance. You should now hear any audio playing on your system (from youtube or iTunes etc) (in fact guarded of logic)
Press R to save it.
-
Random popping / ticking during audio playback
Hey,.
W500 4058-CTO running x 64 Vista Ult using drivers latest 5th Jan.
I feel random noises clicking / popping during audio playback MP3 of WMP11 on speakers/headphones.
If I use my headset Bluetooth AD2P no questions, yes mp3 and WMP is fine.
Someone knows the similar problem?
-
I am facing problem with playback of the audio recorded.
Original title: sound recording problem
Use built in mic, I recorded w/vocals/guitar,... and playback starts well, but after a few seconds the sound loses the basis... or low frequencies.
It is uniform everytime I try. What I am doing wrong?
Rich
[Moved from comments]
Hello
What version of the Windows operating system is installed on your computer?
If I understand correctly you are facing some problem with the audio recorded. There is no way to lose the sound after a few seconds; There seems to be a problem with the registration. I suggest you to run the game audio recording Fixit then try to register once more and check if it works.
Automatically diagnose and fix problems of Windows audio recording:
http://support.Microsoft.com/mats/AudioRecording/
For more information, see the following link:
http://Windows.Microsoft.com/en-us/Windows7/record-audio-with-sound-recorder
Hope the information is useful.
-
Why do I have a loud hum as well as audio recorded when I play a file saved using Microsoft LifeCam with the latest version of Microsoft Essentials?
HUMS are usually ground fault loops.
If it is a test of laptop with and without the power connected (using battery instead)
The mic can also have a cut wire, etc.
-
Access to / computers sound card audio recording
I can't find any support for access to and the audio recording of his computrers card. I want to save her with an AVI file, for example, while documentary about a process. I have a complete program for the video portion and wish I could increase my program with audio.
First of all, is it possible with Labview standard (8.5) and Imaq Toolbox, and if yes, can anyone point to where it can be written to help understand how?
Look in the 'Graphics & Sound' Sound palette' - you should find screws for obtaining sound sound card and also the screw to write to a .wav file.
Then you'll want over them something like this (just for illustration, not tested - I was not even wire a stop button):
Good luck
Simon
-
original title: sound problems
Hello!
I tried to record some live audio. I downloadedWondershare Streaming Audio Recorder
I opened the program - but could not hear the audio that I tried to play. I don't know if downloading this program is related to the problem.I opened Skype - and everything worked fine. I could hear, etc. But if I run an MP3 in Windows Media Player - I hear nothing!My sound is at the top.In my Volume mixer, I see:1 output device digital (SPDIF) bounce up and down. (but I don't)2 but applications: sounds of Windows, Windows Media Player and Google Chrome will not move. (but they are at the top).Any suggestions?JewsI managed to get the results of work. I don't know where come the SPDIF.
I downloaded a new driver Realtek for audio from the computer. This corrects the problem.But I still want to know what happened. -
Abgesehen von dem Audio Recorder bin ich mit danke, aber ich recorder would so like den alten XP Vista. Kann ich den herkriegen und auf installieren Vista irgenwo?
I'm sorry, but these Vista Help Forums only provide support in English.
http://support.Microsoft.com/common/international.aspx
To ensure that you receive support appropriate for your location information, select your region setting in the list on the link above and then click the arrow button.
Thank you.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
XP forums:
http://social.answers.Microsoft.com/forums/en-us/category/WindowsXP
Link above is for XP Forums.
There is a list of the different Forums XP to the link above to help you.
You get the help you need there.
Here is the Vista Forums.
Thank you.
Mick Murphy - Microsoft partner
-
Windows media player does not automatically open a video file on a Web site but I save it and open the file with Windows media player to play the video or audio recording. I used to be able to play any video or audio file in any site!
Hello
Try resetting the default associations for WMP and IE.
How to set default Associations for a program under Vista
http://www.Vistax64.com/tutorials/83196-default-programs-program-default-associations.html
How to associate a file Type of Extension to a program under Vista
http://www.Vistax64.com/tutorials/69758-default-programs.htmlIf necessary:
How Unassociate a Type of Extension file in Vista - and a utility to help
http://www.Vistax64.com/tutorials/91920-unassociate-file-extention-type.html
Restore the Type Associations by default Vista file extensions
http://www.Vistax64.com/tutorials/233243-default-file-type-associations-restore.html
How to view and change an Extension of filename on Vista
http://www.Vistax64.com/tutorials/103171-file-name-extension.html====================================
Also follow these steps:
Follow these steps to remove corruption and missing/damaged file system repair or replacement.
Run DiskCleanup - start - all programs - Accessories - System Tools - Disk Cleanup
Start - type in the search box - find command top - RIGHT CLICK – RUN AS ADMIN
sfc/scannow
How to analyze the log file entries that the Microsoft Windows Resource Checker (SFC.exe) program
generates in Windows Vista cbs.log
http://support.Microsoft.com/kb/928228Then, run checkdisk - schedule it to run at next boot, then apply OK your way out, then restart.
How to run the check disk at startup in Vista
http://www.Vistax64.com/tutorials/67612-check-disk-Chkdsk.html------------------------------------------------------------
Then, if necessary:
Have you recently installed another player?
Reset your associations for WMP and IE.
How to set default Associations for a program under Vista
http://www.Vistax64.com/tutorials/83196-default-programs-program-default-associations.html
How to associate a file Type of Extension to a program under Vista
http://www.Vistax64.com/tutorials/69758-default-programs.html---------------------------------------------
Do this to reregister the Jscript.dll and Vbscript.dll files.
Start - type in the search box - find command top - RIGHT CLICK – RUN AS ADMIN
type or copy and paste-> regsvr32 jscript.dll
Press entertype or copy and paste-> regsvr32 vbscript.dll
Press enterRestart and if all goes well, it will run now.
--------------------------------------------------------------
Have you recently added stores or ANY application from Stardock?
Using 64-bit Vista?
Can you think of recent things you did in WMP which could be the cause? You added another
reader recently or an add-on for WMP?When I try to use Windows Media Player 11, the program does not start, or some UI elements
are empty - a Mr Fixit
http://support.Microsoft.com/kb/925704/en-usMaybe something here
http://msmvps.com/blogs/chrisl/articles/17315.aspx
and here
http://msmvps.com/blogs/chrisl/Archive/2004/10/30/17399.aspxCheck here the news of WMP11
http://zachd.com/PSS/PSS.htmlI hope this helps.
I hope this helps.
Rob - bicycle - Mark Twain said it is good.
Maybe you are looking for
-
Toshiba 32D3453DB: News banner does not display details program change
Hello I just bought a new 32D3453DB TV / DVD combo and notice that when changing channels the banner at the bottom of the screen only displays all information about the current program (it does is display the channel name and the rest is blank). If I
-
Satellite A300-29N - auto restart within a time
Hello I have laptop Toshiba Satellite A300-29N, recently, I noticed that my laptop auto-redémarre after 5 minutes, I thought that this could be a problem of charger so I replaced it, and nothing has changed, so I thought that maybe the power so I plu
-
HP 255 G3: I can not enter Setup with administrator password
I can't get into Setup with administrator password When I go into Setup it gives to enter the administrator password. (I forget) HP 255 g3 System disabled: 67365449
-
ConfigFree is unable to control the wireless adapter
Hi I have a problemI have two routers in my housethe connection is interrupted frequently, one router to anotherI tried to disable the device windows wireless, then configfree shows a msg that asked to another provider controlling the wireless card,I
-
YouTube displays do not all photos, logos, photos.
Today, I open my youtube page to find like this: What is the solution