View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Playing Multiple Sounds Using JMF

It is possible to make a java applet to play the mp3s. There are still some issues with getting jmf to work under linux (on the client side), but we know that it works in both Netscape and IE in Windows..

Your squeak would have to serve a page that looks something like this:

<HTML>
<HEAD>
<TITLE>Applet Test</TITLE>
</HEAD>
<BODY>
<applet code=StreamingPlayerApplet
classpath=http://toaster.resnet.gatech.edu/jmf.jar width=320 height=300> 
<param name=FILE0 value="1.mp3">
<param name=FILE1 value="Getmeouttahere.aiff">
<param name=FILE2 value="drgnet01.wav">
<param name=FILE3 value="getaway.mid">
</applet>
</BODY>

as well as the applet files themselves.. to use this you need to

  1. download the jmf from sun
  2. download the browser plugin from sun (http://java.sun.com/jmf as I recall)
  3. use the below class (also available from http://toaster.resnet.gatech.edu/StreamingPlayerApplet.java)


If you find out how to make it work with linux on the client side, follow up and let people know..

(note that since this is jmf stuff, it would also work for avis, mpeg movies, etc)

import java.applet.Applet;
import java.awt.*;
import java.lang.String;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.IOException;
import javax.media.*;
import java.util.*;
/* Most of this code ws borrowed from Sun's TypicalPlayerApplet 
 * demo in the JMF documentation.
 * It has been modified to fit the multiple file playing needs
 * of CS2340 by Andrew Hilton (adhilton@cc.gatech.edu)
 * questions and comments are welcome.
 */

public class StreamingPlayerApplet extends Applet implements ControllerListener
{
    // media player    
    Player player = null;  
    
    // component in which video is playing             
    Component visualComponent  = null;   
    // controls gain, position, start, stop
    Component controlComponent = null;   
    // displays progress during download
    Component progressBar      = null;  
    String[] fileList =null;
    int currFile=0;
    /**
     * Read the applet file parameter and create the media
     * player.
     */
    private void openFile(String name)
    {
	// URL for our media file
	URL url = null;  
	// URL for doc containing applet               
	URL codeBase = getDocumentBase();  
	try 
	    {
		// Create an url from the file name and the url to the 
		// document containing this applet.
		
		if ((url = new URL(codeBase, name)) == null)
		    Fatal("Can't build URL for " + name);
		
		// Create an instance of a player for this media
		if ((player = Manager.createPlayer(url)) == null)
                     Fatal("Could not create player for "+url);
		
		// Add ourselves as a listener for player's events
		player.addControllerListener(this);
	    } 
	catch (MalformedURLException u) 
	    {
		Fatal("Invalid media file URL!");
	    } 
	catch(javax.media.NoPlayerException npe)
	    {
		Fatal("No player available");
	    }
	catch(IOException i) 
               {
		   Fatal("IO exception creating player for "+url);
               }
    }
    public void init() 
    {
	setLayout(new BorderLayout());
	// input file name from html param
	String mediaFile = null;        
	
	// Get the media filename info.
	// The applet tag should contain the path to the
	// source media file, relative to the html page.
	int i=0;
	
	while(getParameter("FILE"+i)!=null)
	    {
		i++;
	    }
	if (i==0)
	    Fatal("Invalid media file parameter");
	fileList=new String[i];
	for(i=0;i=fileList.length)
		    currFile=0;
		openFile(fileList[currFile]);
		player.start();
	    }
	else if (event instanceof ControllerErrorEvent) 
	    {
		// Tell TypicalPlayerApplet.start() to call it a day
		
		player = null;
		Fatal (((ControllerErrorEvent)event).getMessage());
	    }
    }
    
    void Fatal (String s) 
    {
	// Applications will make various choices about what
	// to do here.  We print a message and then exit
	
	System.err.println("FATAL ERROR: " + s);
	throw new Error(s);  // Invoke the uncaught exception
	// handler System.exit() is another 
	// choice
    }
}


Link to this Page