Skip to main content

audio and mediaComponent

3 replies [Last post]
seik
Offline
Joined: 2008-07-03
Points: 0

I'm trying to use the mediaComponent to play an audio but I'm getting a null point exception. Can you tell me what's wrong on my code?plz^^

try {
System.out.println("start");
setLayout(new BorderLayout());
InputStream is = getClass().getResourceAsStream("/sounds/audiTst.wav");
System.out.println("getIS");
Player player = Manager.createPlayer(is, "audio/x-wav");
player.realize();
System.out.println("Create Player");
MediaComponent mediaComp;
mediaComp = new MediaComponent(player);//the null happends here
mediaComp.setLoopCount(3);
System.out.println("Create MC");
addComponent(BorderLayout.CENTER,mediaComp);
System.out.println("add MC");
mediaComp.start();
//player.prefetch();
//player.start();
System.out.println("startMC");
} catch (IOException e) {
e.printStackTrace();
} catch (MediaException e) {
e.printStackTrace();
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pschar
Offline
Joined: 2008-05-30
Points: 0

The problem is that LWUIT makes this call on your Player:

vidc = (VideoControl)Display.getInstance().getVideoControl(player);

which results in this call:

VideoControl vidc = (VideoControl)((Player)player).getControl("VideoControl");

It doesn't work so well on an audio player.

Shai Almog

There is no need for MediaComponent for audio, there is no use case
for that. Just use the MMAPI as you normally would.
MediaComponent exists so the VideoControl can be mapped into the UI
abstracted by LWUIT.

> The problem is that LWUIT makes this call on your Player:
>
> vidc = (VideoControl)Display.getInstance().getVideoControl(player);
>
> which results in this call:
>
> VideoControl vidc = (VideoControl)((Player)player).getControl
> ("VideoControl");
>
>
> It doesn't work so well on an audio player.
> [Message sent by forum member 'pschar' (pschar)]
>
> http://forums.java.net/jive/thread.jspa?messageID=315558
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

pschar
Offline
Joined: 2008-05-30
Points: 0

Certainly there is a use case. I found this out when I tried it, hoping LWUIT would show a visual timeline/progress indicator as my audio played. It's no big deal, but it would be nice if the documentation mentioned LWUIT would throw an ugly exeption when given a non-video player.