Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #14339 > unrolled thread

i want to play mp3 for infinite time

Started bychetan1991@gmail.com
First post2012-05-06 10:10 -0700
Last post2012-05-07 21:54 -0700
Articles 6 — 4 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  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

#14339 — i want to play mp3 for infinite time

Fromchetan1991@gmail.com
Date2012-05-06 10:10 -0700
Subjecti want to play mp3 for infinite time
Message-ID<22351436.624.1336324248195.JavaMail.geo-discussion-forums@pbctc10>
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    
    
    
  */

[toc] | [next] | [standalone]


#14342

From"Gavino" <invalid@invalid.invalid>
Date2012-05-06 21:34 +0200
Message-ID<a0o22pF437U1@mid.individual.net>
In reply to#14339
<chetan1991@gmail.com> wrote in message
news:22351436.624.1336324248195.JavaMail.geo-discussion-forums@pbctc10...
> I want to play my mp3 file for infinite times,
> help me to play this for infinite time in loop.

>             public void controllerUpdate(ControllerEvent e)
>                 {
>                     if (e instanceof EndOfMediaEvent)
>                     {
>                         playMP3.stop();
>                         playMP3.close();

Instead of closing the player, you should do this:
    playMP3.setMediaTime(new Time(0));
    playMP3.start();

[toc] | [prev] | [next] | [standalone]


#14349

FromLew <noone@lewscanon.com>
Date2012-05-06 21:00 -0700
Message-ID<jo7hdc$rhf$1@news.albasani.net>
In reply to#14342
Gavino wrote:
> chetan1991 wrote ...
>> I want to play my mp3 file for infinite times,
>> help me to play this for infinite time in loop.
>
>>              public void controllerUpdate(ControllerEvent e)
>>                  {
>>                      if (e instanceof EndOfMediaEvent)
>>                      {
>>                          playMP3.stop();
>>                          playMP3.close();
>
> Instead of closing the player, you should do this:
>      playMP3.setMediaTime(new Time(0));
>      playMP3.start();

Also, follow the Java naming and source indentation conventions.

<http://www.oracle.com/technetwork/java/codeconv-138413.html>

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

[toc] | [prev] | [next] | [standalone]


#14351

FromKnute Johnson <nospam@knutejohnson.com>
Date2012-05-06 21:46 -0700
Message-ID<jo7k3s$oke$1@dont-email.me>
In reply to#14349
On 5/6/2012 9:00 PM, Lew wrote:
> Gavino wrote:
>> chetan1991 wrote ...
>>> I want to play my mp3 file for infinite times,
>>> help me to play this for infinite time in loop.
>>
>>> public void controllerUpdate(ControllerEvent e)
>>> {
>>> if (e instanceof EndOfMediaEvent)
>>> {
>>> playMP3.stop();
>>> playMP3.close();
>>
>> Instead of closing the player, you should do this:
>> playMP3.setMediaTime(new Time(0));
>> playMP3.start();
>
> Also, follow the Java naming and source indentation conventions.
>
> <http://www.oracle.com/technetwork/java/codeconv-138413.html>
>

He's going to need the Java MP3 plugin and I can't find it on Oracle's 
website.  Any idea where it is now?  I've still got a copy and it works 
fine for MPEG2 layer 3 audio files even for JavaSound.

-- 

Knute Johnson

[toc] | [prev] | [next] | [standalone]


#14371

From"Gavino" <invalid@invalid.invalid>
Date2012-05-07 19:36 +0200
Message-ID<a0qfhhF5p8U1@mid.individual.net>
In reply to#14351
"Knute Johnson" <nospam@knutejohnson.com> wrote in message
news:jo7k3s$oke$1@dont-email.me...
> He's going to need the Java MP3 plugin and I can't find it on Oracle's
> website.  Any idea where it is now?

I imagine he's got it since he said he was able to play the file once
(ie without looping).

Anyway, it can be found at:
http://www.oracle.com/technetwork/java/javase/download-137625.html



[toc] | [prev] | [next] | [standalone]


#14389

FromKnute Johnson <nospam@knutejohnson.com>
Date2012-05-07 21:54 -0700
Message-ID<joa8v1$t2u$1@dont-email.me>
In reply to#14371
On 5/7/2012 10:36 AM, Gavino wrote:
> "Knute Johnson"<nospam@knutejohnson.com>  wrote in message
> news:jo7k3s$oke$1@dont-email.me...
>> He's going to need the Java MP3 plugin and I can't find it on Oracle's
>> website.  Any idea where it is now?
>
> I imagine he's got it since he said he was able to play the file once
> (ie without looping).
>
> Anyway, it can be found at:
> http://www.oracle.com/technetwork/java/javase/download-137625.html

It's not actually there.  That page takes you to another that has JMF 
and JAI but no MP3 plugin.

-- 

Knute Johnson

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web