FileDocCategorySizeDatePackage
DirectVolume.javaAPI DocphoneME MR2 API (J2ME)3924Wed May 02 16:47:08 BST 2007com.sun.mmedia

DirectVolume

public class DirectVolume extends Object implements VolumeControl
Native volume control implementation

Fields Summary
private int
_level
private int
_mute
private int
_hNative
private BasicPlayer
_player
Constructors Summary
DirectVolume(BasicPlayer player, int hNative)


        
        _player = player;
        _hNative = hNative;
    
Methods Summary
public intgetLevel()

        if (_level == -1) {
            _level = nGetVolume(_hNative);
        }
        return _level;
    
public booleanisMuted()

        if (_mute != -1) return (_mute == 1);
        if (true == nIsMuted(_hNative)) {
            _mute = 1;
            return true;
        } else {
            _mute = 0;
            return false;
        }
    
protected native intnGetVolume(int hNative)

protected native booleannIsMuted(int hNative)

protected native booleannSetMute(int hNative, boolean mute)

protected native intnSetVolume(int hNative, int level)

public intsetLevel(int level)

        if (level < 0) {
            if (Logging.REPORT_LEVEL <= Logging.ERROR) {
                Logging.report(Logging.ERROR, LogChannels.LC_MMAPI, 
                    "volume level " + level + " is negative, change to 0");
            }
            level = 0;
        } else if (level > 100) {
            if (Logging.REPORT_LEVEL <= Logging.ERROR) {
                Logging.report(Logging.ERROR, LogChannels.LC_MMAPI, 
                    "volume level " + level + " is too big, change to 100");
            }
            level = 100;
        }

        // Volume value is same. just return.
        if (_level == level) {
            return _level;
        }

        // If this player is not started yet, this new volume will be setted 
        // when this player start
        if (_player.state == Player.STARTED) {
            if (-1 == nSetVolume(_hNative, level)) {
                if (Logging.REPORT_LEVEL <= Logging.ERROR) {
                    Logging.report(Logging.ERROR, LogChannels.LC_MMAPI, 
                        "set volume failed volume=" + _level);
                }
            }
        }

        _level = level;
        _player.sendEvent(PlayerListener.VOLUME_CHANGED, this);
        
        return _level;
    
public voidsetMute(boolean mute)

        if (_player.state == Player.STARTED) {
            nSetMute(_hNative, mute);
        }
        _mute = mute ? 1 : 0;
    
voidsetToPlayerMute()

        if (_mute == -1) return;
        nSetMute(_hNative, _mute == 1);
    
voidsetToThisPlayerLevel()

        if (_level == -1) return;
        nSetVolume(_hNative, _level);