Olá Estou desenvolvendo uma aplicação para TV digital, e uso o emulador XLetview. O vídeo necessita ser parado pelo usuário, quando ele quiser via controle remoto, e não estou conseguindo que isso aconteça. Por favor, ajudem-me! Segue o código:
package tcc_ii;
import java.awt.*;
import java.awt.event.*;
import javax.tv.xlet.*;
import org.havi.ui.*;
import org.havi.ui.event.*;
import java.awt.Component;
import java.awt.Rectangle;
import java.io.IOException;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.EndOfMediaEvent;
import javax.media.Manager;
import javax.media.MediaException;
import javax.media.Player;
import javax.media.RealizeCompleteEvent;
import javax.media.Time;
import javax.media.protocol.DataSource;
import javax.tv.xlet.Xlet;
import javax.tv.xlet.XletContext;
import javax.tv.xlet.XletStateChangeException;
import org.havi.ui.*;
/**
*
* @author root
*/
public class Rep_a extends HContainer implements Xlet, ControllerListener, KeyListener {
//private static final String VIDEO_URL_2 = "file://root/NetBeansProjects/UmVideo/build/classes/meuvideo.avi";
static final String VIDEO_URL_2 = "file://C://Users//Vinícius Torres//Videos//rep1.avi";
HScene scene;
Player player;
News ne ;
private XletContext context;
public void initXlet(XletContext arg0) throws XletStateChangeException {
System.out.println("DENTRO ----------initXlet.........."+VIDEO_URL_2);
criaScene();
}
public void criaScene() {
System.out.println("DENTRO DE CRIASCENE................: " + scene);
// Build a full-screen HSceneTemplate.
HSceneTemplate hst = new HSceneTemplate();
hst.setPreference(HSceneTemplate.SCENE_SCREEN_DIMENSION,
new org.havi.ui.HScreenDimension(1, 1),
HSceneTemplate.REQUIRED);
hst.setPreference(HSceneTemplate.SCENE_SCREEN_LOCATION,
new org.havi.ui.HScreenPoint(0, 0),
HSceneTemplate.REQUIRED);
// Now get our HScene.
HSceneFactory hsceneFactory = HSceneFactory.getInstance();
scene = hsceneFactory.getFullScreenScene(HScreen.getDefaultHScreen().getDefaultHGraphicsDevice());
System.out.println("DENTRO DE CRIASCENE................: " + scene.toString());
// If we can't get an HScene that meets our needs, die.
if (scene == null) {
try {
throw new XletStateChangeException("Can't create HScene");
} catch (XletStateChangeException ex) {
ex.printStackTrace();
}
}
// If we have got a suitable HScene, set our size to be the full size of
// the HScene and add ourselves to it.
Rectangle rect = scene.getBounds();
setBounds(rect);
setBounds(10, 10, 720, 576);
scene.setVisible(false);
scene.add(this);
System.out.println("DENTRO DE CRIASCENE.....FIM...........: " + rect);
}
public void startXlet() throws XletStateChangeException {
javax.media.MediaLocator locator;
//Set our scene to be visible. Later in the Xlet we will put the video
// in an HComponent, so we need a visible HScene in which to display it.
System.out.println("fora de startScene...1: " + scene.getSceneTemplate());
scene.setVisible(true);
System.out.println("fora de startScene...2: " + scene.getSceneTemplate());
try {
// Create a data source for our locator. We could create the player
// directly by calling Manager.createPlayer() with the MediaLocator if we
// preferred - the effect is the same.
locator = new javax.media.MediaLocator(VIDEO_URL_2);
DataSource playingDataSource = Manager.createDataSource(locator);
// Now create the player
player = Manager.createPlayer(playingDataSource);
// Add ourselves as a listener for events from the player
player.addControllerListener(this);
// Start the player. At this point, any video would be played in the
// background on a normal MHP or OCAP receiver.
System.out.println("starting...");
player.start();
} catch (IOException e) {
e.printStackTrace();
} catch (MediaException e) {
e.printStackTrace();
}
}
/* Método de java.awt.event.KeyListener */
public void keyTyped(KeyEvent keyevent) {
/* Método vazio */
}
/* Método de java.awt.event.KeyListener */
public void keyReleased(KeyEvent keyevent) {
/* Método vazio */
}
/* Método de java.awt.event.KeyListener */
public void keyPressed(KeyEvent e) {
HSceneFactory hsceneFactory = HSceneFactory.getInstance();
scene = hsceneFactory.getFullScreenScene(HScreen.getDefaultHScreen().
getDefaultHGraphicsDevice());
scene.setSize(640, 480);
scene.setLayout(null);
scene.addKeyListener(this);
String mensagem = "";
int codigo = e.getKeyCode();
/*
* 403 - vermelho
* 404 - verde
* 405 - amarelo
* 406 - azul
*
* 27 - exit
* * (asterisco) - 151
* # (grade) - 520
*
* seta para cima - 38
* seta para baixo - 40
* seta para esquerda - 37
* seta para direita - 39
* ok - 10
*
* números - número + 48 (ex. 2 é 50)
*
*/
switch (codigo) {
case 27:
try
{
}
catch (Exception ex)
{
System.out.println("ERRO: " + ex.getMessage() + ex.getStackTrace());
}
break;
}
}
public void pauseXlet() {
}
public void destroyXlet(boolean unconditional)
throws XletStateChangeException {
if (scene!=null) {
scene.setVisible(false);
scene.removeAll();
scene = null;
}
context.notifyDestroyed();
}
public void controllerUpdate(ControllerEvent event) {/* o problema deve estar aqui*/
Component comp = null;
if (event instanceof RealizeCompleteEvent) {
// Try to display the video in a window (admittedly, a full-screen window)
// Calling getVisualComponent() will convert the player from a
// 'background player' (which plays its video in the video plane)
// to a 'component player' (which plays its video in an AWT component).
// This is a one-way operation, so the only way to go back is to
// destroy the current player and create a new one. If the operation
// fails, then the player will remain as a background player.
if ((comp = player.getVisualComponent()) != null) {
add(comp);
System.out.println("Added " + comp + " as a video component");
// Set the size and position (full screen, placed in the top left corner)
// and draw it.
comp.setSize(700, 556);
setSize(700, 556);
}
} else if (event instanceof EndOfMediaEvent) {
// We've reached the end of the media; rewind and
// start over.
// Note that setMediaTime() will NOT work in this way on a real MHP
// implementation. The concept of 'media time' has no real meaning in a
// broadcast environment, and so xlets can only set the media time of
// audio clips that are played from a file.
player.stop();
player.close();
try
{
ne.initXlet(context);
ne.startXlet();
}
catch (Exception ex)
{
System.out.println("ERRO: " + ex.getMessage() + ex.getStackTrace());
}
}
/* else if (event instanceof ControllerClosedEvent) {
try
{
ne.initXlet(context);
ne.startXlet();
}
catch (Exception ex)
{
System.out.println("ERRO: " + ex.getMessage() + ex.getStackTrace());
}
}*/
}
public static void main(String[] args){
new Rep_a ();
}
}
Desde já, agradeço pela atenção!
Vinícius Torres