[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3464
  • Last Modified:

Java Program that plays wma files

This Java Program suppose to play wma files. However when I run my class I get errors.

Here is the program

_______________________________________________________________

// Imports
import java.applet.*;
import java.awt.*;
import java.util.Random;

public class MyMusicFiles extends Applet implements Runnable {
  AudioClip clip[] = new AudioClip[5];
  Thread    thread;
  Random    rand = new Random(System.currentTimeMillis());

  public void init() {

      clip[0] = getAudioClip(getDocumentBase(), "c:\Penny Lane.wma");
      clip[1] = getAudioClip(getDocumentBase(), "c:\Like a Rolling Stone.wma");
      clip[2] = getAudioClip(getDocumentBase(), "c:\You Shook Me.wma");
      clip[3] = getAudioClip(getDocumentBase(), "c:\Communication Breakdown.wma");
      clip[4] = getAudioClip(getDocumentBase(), "c:\Whole Lotta Love.wma");
  }

  public void start() {
    if (thread == null) {
      thread = new Thread(this);
      thread.start();
    }
  }

  public void stop() {
    if (thread != null) {
      thread.stop();
      thread = null;
    }
  }

  public void run() {
    while (Thread.currentThread() == thread) {
      // Loop the music sound
      clip[0].loop();

      while (true) {
        // Wait three seconds
        try {
          Thread.sleep(3000); }
        catch (InterruptedException ie) {
                 System.out.println(ie);}
        break;

        // Play an animal sound
        clip[(rand.nextInt() % 3) + 4].play();
      }
    }
  }

  public void paint(Graphics g) {
    Font        font = new Font("TimesRoman", Font.PLAIN, 20);
    FontMetrics fm = g.getFontMetrics(font);
    String      str = new String("On the farm...");
    g.setFont(font);
    g.drawString(str, (size().width - fm.stringWidth(str)) / 2,
      ((size().height - fm.getHeight()) / 2) + fm.getAscent());
  }
}

_______________________________________________________________
This is my MyMusicFiles.html

<HTML>
<HEAD>
<TITLE>A Simple Program</TITLE>
</HEAD>
<BODY>
Here is the output of my program:
<APPLET CODE="MyMusicFiles.class" WIDTH=150 HEIGHT=25>
</APPLET>
</BODY>
</HTML>

________________________________________________________________

When I run it I get these errors

C:\java>appletviewer MyMusicFiles.html
java.lang.NullPointerException
        at MyMusicFiles.run(MyMusicFiles.java:46)
        at java.lang.Thread.run(Thread.java:479)


Any ideas please

I compile the program with the following command

javac -d MyMusicFiles.java

Thanks
0
nickmcdonald
Asked:
nickmcdonald
  • 6
  • 4
  • 3
1 Solution
 
CEHJCommented:
Not sure if that file type is supported but that should be more like

clip[0] = getAudioClip(getDocumentBase(), "Penny Lane.wma");
0
 
nickmcdonaldAuthor Commented:
No its still not working please help  me to play wma files through this Java Program.

Thanks
0
 
CEHJCommented:
Put the files in the same directory as the applet and try

clip[0] = getAudioClip(getCodeBase(), "Penny Lane.wma");
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nickmcdonaldAuthor Commented:
I copy all the music file in the same dir where this program however still having the same problem. Here

C:\java>appletviewer MyMusicFiles.html
java.lang.NullPointerException
        at MyMusicFiles.run(MyMusicFIles.java:46)
        at java.lang.Thread.run(Thread.java:479)


Please need help to play wma files.

THANKS
0
 
objectsCommented:
Applet do not support playing wma files.
0
 
nickmcdonaldAuthor Commented:
Since Applet do not support to play wma files, is there anyone can tell me how I can change this application so that I don't need to use applet. Therefore program will play wma files?

THANKS!!
0
 
nickmcdonaldAuthor Commented:
Well I have been having difficulties to play wma files from using the above java program.

Question is  there anyone can tell me how I can implement a Java program that will run in my PC or Network and picked up any music files such as MP3, wma, wva, midi (any kind of audio file) and play them.

This program will scan all the directories either on the PC or Network and run any kind of audio file.

Once it done playing a file then its pick up next audio file that is either in the same directory or in another directory.

The program ends when its done scanning all the directories and done playing all the music files.

Thanks in advance for your kind help!!!
0
 
CEHJCommented:
You will need to obtain libraries for Java that support the various file formats and then integrate them into a signed applet
0
 
nickmcdonaldAuthor Commented:
THANKS, however I have no clue where to start. Could you please tell explain be with some sample examples and then I can take it and enhance from there.

I would be monumental help.
0
 
CEHJCommented:
You could start by looking on sourceforge for libraries for various file formats:

http://sourceforge.net/search/?type_of_search=soft&exact=1&forum_id=0&group_id=0&atid=0&words=java+mp3+file&Search=Search
0
 
objectsCommented:
You're not going to be able to support every format, suggest you start with the supported formats and build from there :)
0
 
nickmcdonaldAuthor Commented:
I appreciated that you send me this link however I have no clue where to start. So

Is there anyone who can give me a sample program lets say that will play mp3 files or wma files?

In that case I have something ti start with.

Thanks in advance.

Nick
0
 
objectsCommented:
for mp3 try:
http://www.javazoom.net/javalayer/javalayer.html

am not aware of a wma decoder.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now