Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #14339
| From | chetan1991@gmail.com |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | i want to play mp3 for infinite time |
| Date | 2012-05-06 10:10 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <22351436.624.1336324248195.JavaMail.geo-discussion-forums@pbctc10> (permalink) |
Hello All,
I am Chetan Joshi,
IBAB, Bangalore.
I want to play my mp3 file for infinite times,
help me to play this for infinite time in loop.
i use netBeans to run this program.
import javax.media.*;
import java.io.*;
import java.net.URL;
public class playmp3
{
public static void main(String[] args)
{
mp3 t = new mp3("file:///C://JavaApplications//cd.mp3");
t.start();
/* i have tried to run this, but it player my mp3 file for once only. Hence i commented this
try
{
while(TRUE)
if(t.isAlive())
{t.join();}
else
{
t.join();
}
}
catch(Exception e){}*/
}
}
class mp3 extends Thread
{
private URL url; // Uniform Resource locater - helps in path
private MediaLocator mediaLocator; // related to URL -helps in creatinh play list
private Player playMP3; // interface
public mp3(String mp3)
{
try
{
this.url = new URL(mp3);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public void run()
{
try
{
mediaLocator = new MediaLocator(url);
playMP3 = Manager.createPlayer(mediaLocator);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
playMP3.addControllerListener(new ControllerListener()
{
public void controllerUpdate(ControllerEvent e)
{
if (e instanceof EndOfMediaEvent)
{
playMP3.stop();
playMP3.close();
}
}
}
);
playMP3.realize();
playMP3.start();
}
}
/**
URL:
http://docs.oracle.com/javase/1.4.2/docs/api/java/net/URL.html
MediaLocater:
http://docs.oracle.com/cd/E17802_01/j2se/javase/technologies/desktop/media/jmf/2.1.1/apidocs/javax/media/MediaLocator.html
Player
http://docs.oracle.com/cd/E17802_01/j2se/javase/technologies/desktop/media/jmf/2.1.1/apidocs/javax/media/Player.html
Controller
http://docs.oracle.com/cd/E17802_01/j2se/javase/technologies/desktop/media/jmf/2.1.1/apidocs/javax/media/Controller.html#addControllerListener%28javax.media.ControllerListener%29
Interface clock
http://docs.oracle.com/cd/E17802_01/j2se/javase/technologies/desktop/media/jmf/2.1.1/apidocs/javax/media/Clock.html#RESET
About instanceof
if (objectReference instanceof type)
EndOfMedia
http://java.sun.com/javame/reference/apis/jsr927/javax/media/EndOfMediaEvent.html
*/
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
i want to play mp3 for infinite time chetan1991@gmail.com - 2012-05-06 10:10 -0700
Re: i want to play mp3 for infinite time "Gavino" <invalid@invalid.invalid> - 2012-05-06 21:34 +0200
Re: i want to play mp3 for infinite time Lew <noone@lewscanon.com> - 2012-05-06 21:00 -0700
Re: i want to play mp3 for infinite time Knute Johnson <nospam@knutejohnson.com> - 2012-05-06 21:46 -0700
Re: i want to play mp3 for infinite time "Gavino" <invalid@invalid.invalid> - 2012-05-07 19:36 +0200
Re: i want to play mp3 for infinite time Knute Johnson <nospam@knutejohnson.com> - 2012-05-07 21:54 -0700
csiph-web