Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 25
Registered: ‎07-02-2008
My Device: Not Specified

Audio completely dead after recording and play back for a while

Hi,

 

I'm using JSR 135 to capture and play audio on BlackBerry Perl 8100. We submit audio that we capture over the interface. We also playback audio that we fetch from internet.

 

It seems to work. However, after running the test for a while, audio is completely dead. (Record silent, play with no sound). I don't see any exception thrown. 

 

I have to take the battery out to recover the device to a normal state.

 

Any idea what could cause this problem?

 

Thank you for your help.

  

BlackBerry Development Advisor
Posts: 15,813
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Audio completely dead after recording and play back for a while

What version of BlackBerry handheld software are you seeing this on?  You can see this under Options, About on the BlackBerry.  Can you reproduce this in version 4.5.0?  If so, please provide the steps and or sample code.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Highlighted
New Developer
Posts: 3
Registered: ‎01-05-2009
My Device: Not Specified

Re: Audio completely dead after recording and play back for a while

I'm not the original poster, but we're experiencing the same problem on an 8110 Smartphone running version 4.5.0.55 of the handheld software (Platform 2.7.0.68).

 

Below is the code for a minimal, but self-contained, sample application which will help you reproduce the issue.

 

Here are the steps to reproduce:

 

  1. Build and sign the application. Signing is essential, as the issue becomes more difficult to reproduce if the device asks the user's permission to access the file for playback.
  2. Open the application on an 8110 Smartphone.
  3. Click the navigation wheel. A tone should sound, and the device will have begun recording. The list item text will have changed to "Stop recording".
  4. Click the navigation wheel. The device will begin playing the previously-recorded audio.
  5. Wait for playback to end. The list item text will change to "Start recording".
  6. Keep looping through steps 3 to 5 in rapid succession, performing step 4 as soon as the text changes to "Stop recording" (but not before, or a legitimate exception will be thrown).

 

Before long, the tone will stop sounding, and no audio is recorded or played back. The audio is "completely dead", as the original poster describes.

 

I hope the code is self-explanatory, but please let me know if you have any questions.

 

This issue is a show-stopper as far as our application is concerned, and our customers need to be able to run it on 8110 Smartphones, so I'd be extremely grateful if you could respond as soon as possible.

 

I look forward to your response.

 

 

import java.io.DataOutputStream;

import java.io.IOException;

import javax.microedition.io.Connector;

import javax.microedition.io.file.FileConnection;

import javax.microedition.media.Manager;

import javax.microedition.media.MediaException;

import javax.microedition.media.Player;

import javax.microedition.media.PlayerListener;

import javax.microedition.media.control.RecordControl;

import net.rim.device.api.ui.UiApplication;

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

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

import net.rim.device.api.ui.container.MainScreen;

 

public class AudioTestApp extends UiApplication {

public static void main(String argv[]) {

AudioTestApp app = new AudioTestApp();

app.enterEventDispatcher();

}

 

public AudioTestApp() {

try {

pushScreen(MainMenuScreen.getMainMenuScreen());

} catch (IOException e) {

MainMenuScreen.reportException(e);

}

}

}

 

class Recorder implements PlayerListener {

private String uri;

private FileConnection fileConnection;

private Player player = null;

private boolean isRecording = false;

private RecordControl recordControl = null;

private DataOutputStream outputStream = null;

 

public Recorder(String uri) throws IOException {

this.uri = uri;

fileConnection = (FileConnection) Connector.open(uri,

Connector.READ_WRITE);

if (fileConnection.exists())

fileConnection.delete();

fileConnection.create();

}

 

void record() throws IOException, MediaException {

player = Manager.createPlayer("capture://audio?encoding=audio/amr");

player.addPlayerListener(this);

player.realize();

recordControl = (RecordControl) player.getControl("RecordControl");

fileConnection.truncate(0);

outputStream = fileConnection.openDataOutputStream();

recordControl.setRecordStream(outputStream);

Manager.playTone(69, 500, 100);

try {

Thread.sleep(500); // This prevents the tone from being truncated

} catch (InterruptedException e) { }

recordControl.startRecord();

player.start();

}

 

void stop() throws IOException {

if (recordControl != null) {

recordControl.commit();

recordControl = null;

}

if (outputStream != null) {

outputStream.close();

outputStream = null;

}

if (player != null) {

player.close();

player = null;

}

isRecording = false;

}

 

private void play() throws IOException, MediaException {

player = Manager.createPlayer(uri);

player.addPlayerListener(this);

player.realize();

player.prefetch();

player.start();

}

 

public void playerUpdate(Player player, final String event, Object eventData) {

if (player != this.player)

return;

if (event == PlayerListener.RECORD_STARTED)

isRecording = true;

UiApplication.getUiApplication().invokeLater(new Runnable() {

public void run() {

try {

if (event == PlayerListener.RECORD_STOPPED) {

isRecording = false;

play();

}

MainMenuScreen.getMainMenuScreen().handleAudioEvent(event,

isRecording);

} catch (Exception e) {

MainMenuScreen.reportException(e);

}

}

});

}

}

 

class MainMenuScreen extends MainScreen {

private static MainMenuScreen mainMenuScreen = null;

private ObjectListField listField = new ObjectListField();

private final static short STOPPED = 0, RECORDING = 1, PLAYING = 2;

private short state;

private Recorder recorder;

 

static MainMenuScreen getMainMenuScreen() throws IOException {

if (mainMenuScreen == null)

mainMenuScreen = new MainMenuScreen();

return mainMenuScreen;

}

 

static void reportException(final Exception e) {

e.printStackTrace();

UiApplication.getUiApplication().invokeAndWait(new Runnable() {

public void run() {

Dialog.inform(e.toString());

}

});

}

 

public MainMenuScreen() throws IOException {

super();

recorder = new Recorder("file:///store/home/user/test.amr");

setState(STOPPED);

add(listField);

}

 

protected boolean navigationClick(int status, int time) {

try {

if (state == STOPPED)

recorder.record();

else

recorder.stop();

} catch (Exception e) {

reportException(e);

}

return true;

}

private void setState(short state) {

this.state = state;

String action;

switch (state) {

case RECORDING:

action = "Stop recording";

break;

case PLAYING:

action = "Stop playing";

break;

default: // STOPPED

action = "Start recording";

break;

}

listField.set(new String[] { action });

}

 

void handleAudioEvent(String event, boolean isRecording) {

if (event == PlayerListener.RECORD_STARTED)

setState(RECORDING);

else if (event == PlayerListener.STARTED && !isRecording)

setState(PLAYING);

else if (event == PlayerListener.STOPPED

|| event == PlayerListener.END_OF_MEDIA

|| event == PlayerListener.RECORD_STOPPED)

setState(STOPPED);

}

}

 

 

 


 

 

BlackBerry Development Advisor
Posts: 15,813
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Audio completely dead after recording and play back for a while

I tried testing this on the same BlackBerry model and handheld software version and was unable to reproduce this behaviour.  I tested this by running your sample as you describe and ran it 15-20 times in a row with each test and it worked without issue.

 

Is there anything else happening on your device at the same time?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
New Developer
Posts: 3
Registered: ‎01-05-2009
My Device: Not Specified

Re: Audio completely dead after recording and play back for a while

Thanks for trying that out, Mark. In my experience, whether or not the issue is triggered partly depends upon timing. As far as I can tell, there's nothing much else happening on the device at the same time, and I can still reproduce the issue having turned all the device's connections off.

 

I've produced a new version of the sample application (see code below) with which I can reproduce the issue more consistently.

Here are the steps:

 

  1. Build and sign the application. As above, signing is essential.
  2. Open the application on the device.
  3. Scroll down to "Trigger the bug", and click the navigation wheel.
  4. A tone will sound, and the text of the first menu item will change momentarily.
  5. As soon as the first menu item's text has reverted to "Start recording", click "Trigger the bug" again.
  6. Repeat the previous step until the tone no longer sounds. In my experience it can take up to 20 clicks, but sometimes happens after only one.
 
Let me know whether that works for your device. 
 

import java.io.DataOutputStream;

import java.io.IOException;

import javax.microedition.io.Connector;

import javax.microedition.io.file.FileConnection;

import javax.microedition.media.Manager;

import javax.microedition.media.MediaException;

import javax.microedition.media.Player;

import javax.microedition.media.PlayerListener;

import javax.microedition.media.control.RecordControl;

import net.rim.device.api.ui.UiApplication;

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

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

import net.rim.device.api.ui.container.MainScreen;

 

public class AudioTestApp extends UiApplication {

public static void main(String argv[]) {

AudioTestApp app = new AudioTestApp();

app.enterEventDispatcher();

}

public AudioTestApp() {

try {

pushScreen(MainMenuScreen.getMainMenuScreen());

} catch (IOException e) {

MainMenuScreen.reportException(e);

}

}

}

 

class Recorder implements PlayerListener {

private String uri;

private FileConnection fileConnection;

private Player player = null;

private boolean isRecording = false;

private RecordControl recordControl = null;

private DataOutputStream outputStream = null;

private boolean shouldTriggerBug = false;

 

public Recorder(String uri) throws IOException {

this.uri = uri;

fileConnection = (FileConnection) Connector.open(uri,

Connector.READ_WRITE);

if (fileConnection.exists())

fileConnection.delete();

fileConnection.create();

}

 

void record(boolean shouldTriggerBug) throws IOException, MediaException {

this.shouldTriggerBug = shouldTriggerBug;

player = Manager.createPlayer("capture://audio?encoding=audio/amr");

player.addPlayerListener(this);

player.realize();

recordControl = (RecordControl) player.getControl("RecordControl");

fileConnection.truncate(0);

outputStream = fileConnection.openDataOutputStream();

recordControl.setRecordStream(outputStream);

Manager.playTone(69, 500, 100);

try {

Thread.sleep(500); // This prevents the tone from being truncated

} catch (InterruptedException e) { }

recordControl.startRecord();

player.start();

}

 

void stop() throws IOException {

if (recordControl != null) {

recordControl.commit();

recordControl = null;

}

if (outputStream != null) {

outputStream.close();

outputStream = null;

}

if (player != null) {

player.close();

player = null;

}

isRecording = false;

}

 

private void play() throws IOException, MediaException {

player = Manager.createPlayer(uri);

player.addPlayerListener(this);

player.realize();

player.prefetch();

player.start();

}

 

public void playerUpdate(Player player, final String event, Object eventData) {

if (player != this.player)

return;

if (event == PlayerListener.RECORD_STARTED)

isRecording = true;

UiApplication.getUiApplication().invokeLater(new Runnable() {

public void run() {

try {

if (shouldTriggerBug

&& event == PlayerListener.RECORD_STARTED) {

stop();

shouldTriggerBug = false;

} else if (event == PlayerListener.RECORD_STOPPED) {

isRecording = false;

play();

}

MainMenuScreen.getMainMenuScreen().handleAudioEvent(event,

isRecording);

} catch (Exception e) {

MainMenuScreen.reportException(e);

}

}

});

}

}

 

class MainMenuScreen extends MainScreen {

private static MainMenuScreen mainMenuScreen = null;

private ObjectListField listField = new ObjectListField();

private final static short STOPPED = 0, RECORDING = 1, PLAYING = 2;

private short state;

private Recorder recorder;

 

static MainMenuScreen getMainMenuScreen() throws IOException {

if (mainMenuScreen == null)

mainMenuScreen = new MainMenuScreen();

return mainMenuScreen;

}

 

static void reportException(final Exception e) {

e.printStackTrace();

UiApplication.getUiApplication().invokeAndWait(new Runnable() {

public void run() {

Dialog.inform(e.toString());

}

});

}

 

public MainMenuScreen() throws IOException {

super();

recorder = new Recorder("file:///store/home/user/test.amr");

setState(STOPPED);

add(listField);

}

 

protected boolean navigationClick(int status, int time) {

boolean shouldTriggerBug = listField.getSelectedIndex() == 1;

try {

if (state == STOPPED)

recorder.record(shouldTriggerBug);

else

recorder.stop();

} catch (Exception e) {

reportException(e);

}

return true;

}

 

private void setState(short state) {

this.state = state;

String action;

switch (state) {

case RECORDING:

action = "Stop recording";

break;

case PLAYING:

action = "Stop playing";

break;

default: // STOPPED

action = "Start recording";

break;

}

int sel = listField.getSelectedIndex();

listField.set(new String[] { action, "Trigger the bug" });

listField.setSelectedIndex(sel);

}

 

void handleAudioEvent(String event, boolean isRecording) {

if (event == PlayerListener.RECORD_STARTED)

setState(RECORDING);

else if (event == PlayerListener.STARTED && !isRecording)

setState(PLAYING);

else if (event == PlayerListener.STOPPED

|| event == PlayerListener.END_OF_MEDIA

|| event == PlayerListener.RECORD_STOPPED)

setState(STOPPED);

}

}

 

 

 

BlackBerry Development Advisor
Posts: 15,813
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Audio completely dead after recording and play back for a while

[ Edited ]
I ran a few more tests with your updated sample, going up to 30 tests in a row and I wasn't able to trigger the failure.  I tried running it as quickly as possible.  Are there any other timing issues you can see on your side?
Message Edited by MSohm on 01-12-2009 03:02 PM
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
New Developer
Posts: 3
Registered: ‎01-05-2009
My Device: Not Specified

Re: Audio completely dead after recording and play back for a while

Thanks again for that, Mark. Having experimented some more myself, I've found that it can sometimes take up to around 100 presses of "Trigger the Bug" for the issue to appear. It seems to manifest itself more quickly if I've just reset the device by removing and re-inserting the battery, and if running AudioTest is the first thing I do.

I hope that's of some help; let me know how you get on. 

BlackBerry Development Advisor
Posts: 15,813
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Audio completely dead after recording and play back for a while

We have been able to reproduce this issue and it has been sent to our development team.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
New Developer
Posts: 11
Registered: ‎10-12-2008
My Device: Not Specified

Re: Audio completely dead after recording and play back for a while

Hello Mark ,

 

Where can we track the bug and its status. I am also facing the smilar issue..

BlackBerry Development Advisor
Posts: 15,813
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Audio completely dead after recording and play back for a while

We do not have a public bug tracking system.  So there is no place for you to track the status of this issue.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.