BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 10-07-2010, 02:29 PM   #1 (permalink)
New Member
 
Join Date: Oct 2010
Model: 8520
PIN: N/A
Carrier: Digitel
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Volume Contro Null Pointer Exception

Please Login to Remove!

Hey all, i'm new to BB development and im trying to make an audio recording and playback app. I manage to record and stop the recording of the audio well, but when it comes to playing i get a null pointer exception when i call the play() method, specifically in the volume.setLevel() line. Can anyone help? My source code is below:

package Clases;

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

import net.rim.device.api.ui.component.Dialog;

public class AudioRecorderThread extends Thread implements javax.microedition.media.PlayerListener{

private Player _player;
private RecordControl _recordControl;
private ByteArrayOutputStream output;
private ByteArrayInputStream input;

private byte[] _audioArray = null;
public byte[] get_audioArray() {
return _audioArray;
}



AudioRecorderThread()
{
output = new ByteArrayOutputStream();

}


public void playerUpdate(Player player, String event, Object eventData) {
// TODO Auto-generated method stub

}

public void run()
{

try
{
_player = Manager.createPlayer("capture://audio?encoding=audio/amr");
_player.addPlayerListener(this);
_player.realize();
_recordControl = (RecordControl) _player.getControl( "RecordControl" );
_recordControl.setRecordStream(output);
_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)
{

try
{
_recordControl.commit();
_audioArray = output.toByteArray();
}
catch (Exception e)
{
Dialog.alert(e.toString());
}
_recordControl = null;
}
}

public void play()
{

try {
input = new ByteArrayInputStream(_audioArray);
_player = Manager.createPlayer(input, "audio/x-wav");
_player.realize();

VolumeControl volume = (VolumeControl)_player.getControl("Volume Control");
volume.setLevel(50);

_player.prefetch();
_player.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}



}

That's the thread and this is the screen where i call it from:

package Clases;

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


public final class PrincipalScreen extends MainScreen implements FieldChangeListener
{
private ButtonField _boton1,_boton2, _boton3;
private LabelField _label;
private VerticalFieldManager _vertManager;
private HorizontalFieldManager _horiManager1;
private HorizontalFieldManager _horiManager2;
private AudioRecorderThread _recorderThread;



public PrincipalScreen()
{

_vertManager = new VerticalFieldManager();
_horiManager1 = new HorizontalFieldManager();
_horiManager2 = new HorizontalFieldManager();

_vertManager.add(_horiManager1);
_vertManager.add(_horiManager2);

_boton1 = new ButtonField("Record", ButtonField.CONSUME_CLICK);
_boton1.setChangeListener(this);

_boton2 = new ButtonField("Stop", ButtonField.CONSUME_CLICK);
_boton2.setChangeListener(this);

_boton3 = new ButtonField("Play", ButtonField.CONSUME_CLICK);
_boton3.setChangeListener(this);

_label = new LabelField("Choose");

_horiManager1.add(_label);

_horiManager2.add(_boton1);
_horiManager2.add(_boton2);
_horiManager2.add(_boton3);

this.add(_vertManager);

setTitle("Main Screen");

}

public void fieldChanged(Field field, int context)
{
if(field == _boton1)
{
AudioRecorderThread _audioThread = new AudioRecorderThread();
_audioThread.start();
_recorderThread = _audioThread;
// PopScreen popScreen = new PopScreen("Pop");
// UiApplication.getUiApplication().pushScreen(popScr een);
}

if(field == _boton2)
{
try
{
if (_recorderThread != null)
{
_recorderThread.stop();
}
}
catch (Exception e)
{
Dialog.alert(e.toString());
}

}

if(field == _boton3)
{
try
{
if (_recorderThread != null)
{
_recorderThread.play();
}
}
catch (Exception e)
{
Dialog.alert(e.toString());
}

}
}


}
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

MCR-VDC-UI-B-DC PHOENIX CONTACT VOLTAGE TRANSDUCER RELAY MODULE
$49.99
MCR-VDC-UI-B-DC PHOENIX CONTACT VOLTAGE TRANSDUCER RELAY MODULE pictureNEW Transducer Direct TDM52 Series 0-4000 PSIG 0.15-10.15VDC 7/16” X 20 six Pin
$165.99
NEW Transducer Direct TDM52 Series 0-4000 PSIG 0.15-10.15VDC 7/16” X 20 six Pin pictureBarber Colman Electronic Pneumatic Transducer CP-8551 4-20mA DC Direct Acting
$34.99
Barber Colman Electronic Pneumatic Transducer CP-8551 4-20mA DC Direct Acting pictureNEW IN BOX GEFRAN Pressure Probe Transducer 10,000 psi 12-30 VDC ME1-8-H-P10M-1
$129.99
NEW IN BOX GEFRAN Pressure Probe Transducer 10,000 psi 12-30 VDC ME1-8-H-P10M-1 pictureHAROWE SYSTEMS 72164 PRESSURE TRANSDUCER FROM AIR DATA COMPUTER
$79.0
HAROWE SYSTEMS 72164 PRESSURE TRANSDUCER FROM AIR DATA COMPUTER picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.