全体音量を設定するサンプルコード。
本サンプルではJMF Controlであるorg.bluray.media.OverAllGainControlの機能を利用して以下を行っている。
- 全体音量を1秒に1dBの割合で低減
- 全体音量に伴うイベント(GainChangeEvent)を取得
Primary Audioの音量設定と異なり、Interactive Audioの音量も同時に変動することに注目されたい。
Main.java
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import javax.media.Control;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.DurationUpdateEvent;
import javax.media.GainChangeEvent;
import javax.media.GainChangeListener;
import javax.media.Manager;
import javax.media.Player;
import javax.media.PrefetchCompleteEvent;
import javax.media.RealizeCompleteEvent;
import javax.media.StartEvent;
import javax.tv.xlet.Xlet;
import javax.tv.xlet.XletContext;
import net.java.bd.tools.logger.XletLogger;
import org.bluray.media.OverallGainControl;
import org.bluray.media.PrimaryGainControl;
import org.bluray.net.BDLocator;
import org.davic.media.MediaLocator;
import org.havi.ui.HScene;
import org.havi.ui.HSceneFactory;
import org.havi.ui.HScreen;
public class Main implements Xlet, GainChangeListener {
Graphics g = null;
int x=100, y=100;
OverallGainControl pgc = null;
public void initXlet(XletContext xc){
try {
HScene hs= HSceneFactory.getInstance().getFullScreenScene(
HScreen.getDefaultHScreen().getDefaultHGraphicsDevice());
hs.setFont(new Font(null, java.awt.Font.BOLD, 48));
hs.setVisible(true);
hs.requestFocus();
g = hs.getGraphics();
g.setColor(Color.white);
Player player = Manager.createPlayer(new MediaLocator(new BDLocator("bd://1.PLAYLIST:00000")));
Player player2 = Manager.createPlayer(new MediaLocator(new BDLocator("bd://SOUND:00")));
PlayerHelper ph = new PlayerHelper( player );
player.start();
// RealizedEventを待つ必要がある
ph.waitForRealizeComplete();
pgc = (OverallGainControl)player.getControl(OverallGainControl.class.getName());
pgc.addGainChangeListener(this);
// StartEventを待つ必要がある
ph.waitForStart();
for( int i = 0; i < 100; i++ ){
player2.start();
pgc.setDB( pgc.getDB() -1.0f );
Thread.sleep(500);
}
} catch (Exception e){
g.drawString(e.toString(), x, y); y+=50;
}
}
public void startXlet(){}
public void pauseXlet(){ }
public void destroyXlet(boolean unconditional){ }
public void gainChange(GainChangeEvent arg0) {
float level = arg0.getLevel();
float db = arg0.getDB();
g.drawString("gainChange level:"+level+" dB:"+db, x, y); y+=50;
}
// JMF Playerの状態変化待ちを行うためのクラスを定義
class PlayerHelper implements ControllerListener {
Player player = null;
boolean realized = false, prefetched = false, started = false;
public PlayerHelper(Player p){
player = p;
player.addControllerListener(this);
}
public synchronized void controllerUpdate(ControllerEvent arg0) {
if( arg0 instanceof RealizeCompleteEvent ){
realized = true;
notifyAll();
} else if( arg0 instanceof PrefetchCompleteEvent ){
prefetched = true;
notifyAll();
} else if( arg0 instanceof StartEvent ){
started = true;
notifyAll();
}
}
synchronized void waitForRealizeComplete(){
while( !realized )
try {
wait();
} catch (InterruptedException e) {
}
}
synchronized void waitForPrefetchComplete(){
while( !prefetched )
try {
wait();
} catch (InterruptedException e) {
}
}
synchronized void waitForStart(){
while( !started )
try {
wait();
} catch (InterruptedException e) {
}
}
}
}