Skip to main content

NoPlayerException

1 reply [Last post]
em_pleh
Offline
Joined: 2008-12-12
Points: 0

I keep getting NoPlayerException trying to play a MP3, any help would be very appreciated. Thank you in advance.

package hellotvxlet;

import javax.tv.xlet.*;

// We need java.io to read data from files.
import java.io.*;
import java.io.IOException;

// The classes related to graphics and the user interface are scattered across a
// lot of packages. MHP is built on several other standards, and each of these
// tried to fix the problems with AWT that they encountered. MHP adds some
// fixes of its own, resulting in a lot of different packages.
import java.awt.*;
import java.awt.event.*;
import org.havi.ui.*;
import org.havi.ui.event.*;
import org.dvb.ui.*;
import javax.media.*;
import javax.media.Manager;
import javax.media.Player;
import javax.media.protocol.*;
import org.davic.resources.*;
import javax.tv.media.*;
import org.dvb.media.*;
import java.net.URL;

/**
* Just a simple xlet that draws a String in the center of the screen.
*/
public class HelloTVXlet extends HComponent implements Xlet, Runnable, KeyListener {

private XletContext context;
private Thread myWorkerThread;
private HScene scene;
private String message;
private Player player;

/** Creates a new instance of HelloTVXlet */
public HelloTVXlet() {
}

public void initXlet(XletContext ctx) throws javax.tv.xlet.XletStateChangeException {
this.context = ctx;

scene = HSceneFactory.getInstance().getDefaultHScene();

setSize(1920, 1080); // BD screen size
scene.add(this, BorderLayout.CENTER);
scene.validate();
}

public void startXlet() {
setVisible(true);
scene.setVisible(true);
requestFocus();

myWorkerThread = new Thread(this);
myWorkerThread.start();

try {
URL url = new URL("file:///c:/test.mp3");
url.getAuthority();
player = Manager.createPlayer(url);
player.start();

System.out.println("Ended play");

} catch (IOException e) {
e.printStackTrace();
} catch (NoPlayerException e) {
e.printStackTrace();
}

}

public void pauseXlet() {
}

public void destroyXlet(boolean unconditional) throws javax.tv.xlet.XletStateChangeException {
}

public void run() {
message = "Hello World!";

repaint();
scene.repaint();
}

public void paint(Graphics g) {

// Get the size of this component so that we can clear it properly.
Dimension size = getSize();

/* Clear the background of the component to the current
transparency level. Since standard AWT doesn't support
transparency, we have to use an org.dvb.ui.DVBColor
object rather than a java.awt.Color
object */
g.setColor(Color.orange);
g.fillRect(0, 0, size.width, size.height);

g.setFont(new Font("Tiresias", Font.PLAIN, 36));
g.setColor(Color.white);

// Drawing the string may cause an error to get thrown, so we
// surround it with a 'try' block.

g.drawString(message, 200, 350);

}

public void keyPressed(KeyEvent key) {
// What key has been pressed?
switch (key.getKeyCode()) {
// if we have the 'up' key...
case KeyEvent.VK_UP: {
break;
}

case KeyEvent.VK_DOWN: {
break;
}

default: {
// do nothing
break;
}

}
}

public void keyTyped(KeyEvent key) {
// Ignored
}

public void keyReleased(KeyEvent key) {
// Ignored
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
onebeartoe
Offline
Joined: 2011-08-24
Points: 0

Hello, I too am getting a NoPlayerException when trying to play an mp3, but I am seeing this when trying to play the file from a network (HTTP) location. I have used very similar code to what em_pleh has posted here, but using an HTTP URL for the mp3 source (I also used a different HelloWorld app to get started).

I tried a fews ways to start the playback that are triggered when the green, yellow, and blue buttons are pressed. The code is attached.

I have double checked the URL for the MP3 I am trying to play and it is good.

Has anyone had any success playing mp3s from BD-J yet?