BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 10-07-2010, 02:29 PM   #1
8vius
New Member
 
Join Date: Oct 2010
Model: 8520
PIN: N/A
Carrier: Digitel
Posts: 4
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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


CBB65A Round Electric Motor Start Run Capacitor 450VAC 50uf 50MFD Aluminum picture

CBB65A Round Electric Motor Start Run Capacitor 450VAC 50uf 50MFD Aluminum

$9.53



2 PCS of Hard Start Super Boost SPP5 HVAC Relay and Start Capacitor picture

2 PCS of Hard Start Super Boost SPP5 HVAC Relay and Start Capacitor

$18.99



Nichicon Capacitor CE 85C NX 450V 8200uF  picture

Nichicon Capacitor CE 85C NX 450V 8200uF

$54.95



Hummel Run Capacitor # P205 picture

Hummel Run Capacitor # P205

$198.57



6.3V 10V 16V 25V 35V 50V 100V 400V SMD Aluminum Electrolytic Capacitor 1-1000 UF picture

6.3V 10V 16V 25V 35V 50V 100V 400V SMD Aluminum Electrolytic Capacitor 1-1000 UF

$155.59



CBB61 250V  Capacitor 2 wires 1/2/3/3.5/4/5/6/7/8/9/10/12/15/18/20/24/25/30 UF picture

CBB61 250V Capacitor 2 wires 1/2/3/3.5/4/5/6/7/8/9/10/12/15/18/20/24/25/30 UF

$129.95







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