Solved

Java Program that plays wma files

Posted on 2004-08-09
15
3,344 Views
Last Modified: 2013-11-23
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
Comment
Question by:nickmcdonald
  • 6
  • 4
  • 3
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11756106
Not sure if that file type is supported but that should be more like

clip[0] = getAudioClip(getDocumentBase(), "Penny Lane.wma");
0
 

Author Comment

by:nickmcdonald
ID: 11757690
No its still not working please help  me to play wma files through this Java Program.

Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11757758
Put the files in the same directory as the applet and try

clip[0] = getAudioClip(getCodeBase(), "Penny Lane.wma");
0
 

Author Comment

by:nickmcdonald
ID: 11757921
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
 
LVL 92

Expert Comment

by:objects
ID: 11758708
Applet do not support playing wma files.
0
 

Author Comment

by:nickmcdonald
ID: 11763718
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:nickmcdonald
ID: 11767353
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 11767421
You will need to obtain libraries for Java that support the various file formats and then integrate them into a signed applet
0
 

Author Comment

by:nickmcdonald
ID: 11767790
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 11767877
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
 
LVL 92

Expert Comment

by:objects
ID: 11768103
You're not going to be able to support every format, suggest you start with the supported formats and build from there :)
0
 

Author Comment

by:nickmcdonald
ID: 11796303
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
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 11797952
for mp3 try:
http://www.javazoom.net/javalayer/javalayer.html

am not aware of a wma decoder.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 2 42
mapBully challenge 6 89
unix in java example 9 43
HSSFWorkbook cannot be resolved error 10 19
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now