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
BlackBerry Development Advisor
Posts: 15,700
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

PhoneListener and Audio

Quote from previous forum:


Guest
PhoneListener and Audio
Posted: Jul 8, 2008 12:15 PM
Reply
I am helping my enterprise IT build this application for the BB that would play an audio to let users know the duration of the last phone call. The idea is to *politely* lets users know how long they had been on the call after they end it. I am not sure how polite would this be but I did my part of making it sound better by recording the voices in a British accent (thanks to Paul) Smiley Happy

After that I went about creating a background phone listener that intends to play the audio in the
callDisconnected() listener method. The over-simplistic view of the code is listed below. The problem is that I can't seem to play the voice mp3 from the listener methods. If I play the audio from main() it works fine. What am I missing? The powers of RIM and the geniuses of this board, please help!


class MainApp extends UiApplication
{
public static void main(String[] args)
{
pl = MyPhoneListener.waitForSingleton();
Phone.addPhoneListener(pl);
}

private static class MyPhoneListener extends AbstractPhoneListener
{
public void callDisconnected(int callId)
{
Thread voiceThread = new Thread(new PlayVoiceThread());
voiceThread.start();
}
}

class PlayVoiceThread extends Thread {
public void run() {
InputStream str = getClass().getResourceAsStream("/SayFive.mp3");
Player player = javax.microedition.media.Manager.createPlayer
(str, "audio/mpeg");
player.realize();
player.prefetch();
player.start();
}
}
}

 


msohm

Posts: 2,233
Registered: Jul, 2005

Re: PhoneListener and Audio
Posted: Jul 8, 2008 4:15 PM
Reply
What BlackBerry model and handheld software version are you testing on? You can find this under Options, About on the BlackBerry.

Mark Sohm
BlackBerry Developer Journal
www.blackberrydeveloperjournal.com

 

Guest: Mark Wilson
Re: PhoneListener and Audio
Posted: Jul 9, 2008 12:15 AM
Reply
Mark,

Thanks for the reply!

I am using 800 OS ver 4.2.1.72

Thanks!

-M Wilson

 

Guest
Re: PhoneListener and Audio
Posted: Jul 9, 2008 11:25 AM
Reply
Sorry about the typo.

I am using Model 8800/OS ver 4.2.1.72 from ATT.

Thanks!

 

msohm

Posts: 2,233
Registered: Jul, 2005

Re: PhoneListener and Audio
Posted: Jul 10, 2008 2:31 PM
Reply
Your application should extend PhoneListener, not AbstractPhoneLisnter, which is the empty implementation of PhoneListener.

Mark Sohm
BlackBerry Developer Journal
www.blackberrydeveloperjournal.com

 

Guest: Mark Wilson
Re: PhoneListener and Audio
Posted: Jul 10, 2008 11:08 PM
Reply
Thanks Mark, I will try this out tonight and update this thread on what I found.

 

Guest: Mark Wilson
Re: PhoneListener and Audio
Posted: Jul 12, 2008 1:40 AM
Reply
Mark,

I tried implementing PhoneListener in the class that extends UiApplication. But it did not work. Still no audio .

Uploaded files to a friend's website --

MainClass.java
http://tinyurl.com/6oppek

PlayVoiceThread.java
http://tinyurl.com/5o8o9c

Or you can download the whole project here

http://tinyurl.com/5mrajv

I tested your application using the same version and I was able to hear your audio.  Are you receiving the prompt to grant permission when the application registers the PhoneLisenter and fires a PhoneListener method?  You can choose to remember this setting or modify it under Options, Applications, Advanced Options, select your application and choose Edit Permissions.

 

I did notice that using the default settings triggered a prompt when a PhoneListener method was fired within your application (before playing the music).  I had to accept this prompt before the music would play.

 

Please connect your BlackBerry to the BlackBerry JDE, set some break points and verify that you see it running the methods that trigger the audio playback.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker