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

New Contributor
Posts: 9
Registered: ‎05-29-2012
My Device: 8520 curve
My Carrier: Airtel

Setting alram tone programatically


i want to set the tone for alram,so i'm reading a mp3 file from file and using Alert.startAudio(short[],75) method, the problem is i'm reading the file as the byte array and trying to convert it into short array by using the following code.


 int nlengthInSamples = _audioData.length / 2;
            audio_Data = new short[nlengthInSamples];

            for (int i = 0; i < nlengthInSamples; i++) {
               short MSB = (short) _audioData[2*i+1];
               short LSB = (short) _audioData[2*i];
               audio_Data[i] = (short) (MSB << 8 | (255 & LSB));


but it dosen't work,is there any other way wherein i can convert the byte array into short array.


Thanks & Regard,


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

Re: Setting alram tone programatically

An easier approach would be to use the Player class.  Then you'll only need to pass the URL to your mp3 file.

Mark Sohm
BlackBerry Development Advisor

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