ユーザ・プログラムを問わず、字幕が変更された際にイベントを取得するサンプルコード。
当然のことながら、本サンプルで使用するMovie PlayList fileにはPresentation Graphics streamやText subtitle streamが含まれている必要がある。
Main.java
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.EventObject;
import javax.media.Manager;
import javax.media.Player;
import javax.tv.xlet.Xlet;
import javax.tv.xlet.XletContext;
import org.bluray.media.SubtitlingControl;
import org.bluray.net.BDLocator;
import org.davic.media.MediaLocator;
import org.dvb.media.SubtitleListener;
import org.dvb.media.SubtitleNotSelectedEvent;
import org.dvb.media.SubtitleSelectedEvent;
import org.havi.ui.HScene;
import org.havi.ui.HSceneFactory;
import org.havi.ui.HScreen;
public class Main implements Xlet, SubtitleListener {
Graphics g = null;
int x=100, y=100;
SubtitlingControl sc = 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);
g = hs.getGraphics();
g.setColor(Color.white);
Player player = Manager.createPlayer(new MediaLocator(new BDLocator("bd://1.PLAYLIST:00000")));
sc = (SubtitlingControl)player.getControl("org.bluray.media.SubtitlingControl");
sc.addSubtitleListener(this);
player.start();
} catch (Exception e){
g.drawString(e.toString(), x, y); y+=50;
}
}
public void startXlet(){}
public void pauseXlet(){ }
public void destroyXlet(boolean unconditional){ }
public void subtitleStatusChanged(EventObject arg0) {
if( arg0 instanceof SubtitleSelectedEvent ){
String l = sc.getCurrentLanguage();
int n = sc.getCurrentStreamNumber();
g.drawString("StreamNumber:"+ n + " Language:"+l+" is selected", x, y); y+=50;
} else if( arg0 instanceof SubtitleNotSelectedEvent ){
g.drawString("Subtitle is not selected", x, y); y+=50;
}
}
}