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
Contributor
Posts: 14
Registered: ‎09-20-2011
My Device: Developer
My Carrier: Vodafone
Accepted Solution

Strange volume issue playing MP3 with OS 7.1

Hi all,

 

I am having a strange problem when play a mp3 file from my application.

 

I'm using javax.microedition.media.player class, and I know it sounds weird, but after playing the sound 25 times the volume gets lower.

 

The application is compiled with JDE version 5.0, and works without problem on all devices except those with OS version 7.1.

 

I tested in a 9900, a 9860 and a 9810 with OS 7.0 and 7.1, and only detected this problem when the device is running this last, so I believe that not is a code related issue.

 

Also I tried to recompile the application with JDE 7.1, but don't make any difference.

 

Even I set the volume level each time the sound plays:

 

    public boolean play(String fnm, boolean isLoop)
    {  
        if (!isDeviceAvailable) {
            return false;
        }
    
        Player player = (Player) soundsMap.get(fnm);
        if (player == null) {
            return false;
        }
        
        if (player.getState() == Player.STARTED){
            return true;
        }
        
        try {
            if (isLoop)
                player.setLoopCount(-1);
            VolumeControl volumeControl = (VolumeControl) player.getControl("VolumeControl");
            volumeControl.setLevel(volumeLevel);
            player.setMediaTime(-1);
            player.start();
            return true;
        }
        catch(Exception e)
        { System.out.println("Could not play " + fnm);
        return false;
        }
    }  

 

 

Has anyone else noticed this same issue with any of your applications?

Contributor
Posts: 14
Registered: ‎09-20-2011
My Device: Developer
My Carrier: Vodafone

Re: Strange volume issue playing MP3 with OS 7.1

I finally got to find the problem.

 

When you have more that one Player loaded into memory appears this extrange behaviour with the volume.

 

As I say this only occurs with OS 7.1

 

If someone are interested, this simple app get to reproduce the behavior. You only have to load two mp3 files and let them sound, until you appreciate an audible volume change, (no more than 25 or 30 loops in my case)

 

As you can see only the second player is started...

 

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;

public class AudioPlaybackDemo extends UiApplication
{
    public static void main(String[] args)
    {
         AudioPlaybackDemo app = new AudioPlaybackDemo();
         app.enterEventDispatcher();
    }
    
    public AudioPlaybackDemo()
    {
         pushScreen(new AudioPlaybackDemoScreen());
    }

    private class AudioPlaybackDemoScreen extends MainScreen
    {        
        private Player player1;
        private Player player2;
        
        public AudioPlaybackDemoScreen()
        {
            
            try {
                player1 = javax.microedition.media.Manager.createPlayer(getClass().getResourceAsStream("/sounds/sound1.mp3"), "audio/mpeg");
                player1.realize();
                VolumeControl volumeControl1 = (VolumeControl) player1.getControl("VolumeControl");
                volumeControl1.setLevel(70);
                player1.prefetch();
            }
            catch(Exception e) { 
                System.out.println("Exception: " + e);                
            }            
            
            try {
                player2 = javax.microedition.media.Manager.createPlayer(getClass().getResourceAsStream("/sounds/sound2.mp3"), "audio/mpeg");
                player2.realize();      
                VolumeControl volumeControl2 = (VolumeControl) player2.getControl("VolumeControl");
                volumeControl2.setLevel(70);
                player2.prefetch();
                player2.setLoopCount(-1);
                player2.start();
            }
            catch(Exception e) { 
                System.out.println("Exception: " + e);                
            }  
        }         
    }
}