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

RARE Vintage Rainbow Apple Filofax (office folder diary macintosh mac old logo)
$21.99
RARE Vintage Rainbow Apple Filofax (office folder diary macintosh mac old logo) pictureVintage 1/2" Drive MAC VUI 166T 6 Point Impact Swivel Socket
$11.95
Vintage 1/2GW Instruments MacADIOS - Vintage Mac Lab Interface 411
$199.0
GW Instruments MacADIOS - Vintage Mac Lab Interface 411 pictureLot of 18 Sets (36 Speakers) Apple VINTAGE Pro Speakers M6531 iMac Power Mac G4
$49.99
Lot of 18 Sets (36 Speakers) Apple VINTAGE Pro Speakers M6531 iMac Power Mac G4 pictureVINTAGE VELOCETTE MAC MOV GTP KTS MSS FRONT FENDER MUDGUARD STEEL REPRODUCTION@
$172.99
VINTAGE VELOCETTE MAC MOV GTP KTS MSS FRONT FENDER MUDGUARD STEEL REPRODUCTION@ picture






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