[mobility] Re: playing audio files in J2ME using Netbeans 7.1

  • From: "allan" < >
  • To:
  • Subject: [mobility] Re: playing audio files in J2ME using Netbeans 7.1
  • Date: Thu, 09 Feb 2012 08:22:52 +0000

Hello Everyone , 

I'm currently doing a program which play an audio files. 

I encountered two problems 
1. OutofMemory error when playing mp3 files 
* I tried to change the heapsize on the vm options of the netbeans but it 
does'nt work. when ever i run the program I encountered error : Set the 
Security domain 

2. cannot play wav files 

This is my code : 

import java.io.InputStream; 
import javax.microedition.lcdui.*; 
import javax.microedition.media.Manager; 
import javax.microedition.media.MediaException; 
import javax.microedition.media.Player; 
import javax.microedition.midlet.MIDlet; 

public class AudioMidlet extends MIDlet implements CommandListener{ 

private Command exitCommand, playCommand; 
private Form form; 
private Gauge volumeGauge; 
private Display display; 
private int volume = 100; 
private static int MAX_VOLUME = 100; 
Player player; 

public AudioMidlet() { 
playCommand = new Command("Play", Command.OK, 1); 
exitCommand = new Command("Exit", Command.EXIT, 1); 
volumeGauge = new Gauge("Volume", true, MAX_VOLUME, volume); 

form = new Form("Audio Player"); 
form.addCommand(playCommand); 
form.addCommand(exitCommand); 
form.append(volumeGauge); 


public void startApp() { 
display = Display.getDisplay(this); 
form.setCommandListener(this); 
display.setCurrent(form); 



public void pauseApp() {} 
public void destroyApp(boolean unconditional) {} 

public void commandAction(Command c, Displayable d) { 
if (c == exitCommand) { 
notifyDestroyed(); 

if (c == playCommand){ 
try{ 


InputStream stream = getClass().getResourceAsStream("BONG.wav"); 
player = Manager.createPlayer( "audio/wav"); 




player.realize(); 
player.prefetch(); 
player.start(); 
player.stop(); 
player.deallocate(); 
player.close(); 

// VolumeControl control = (VolumeControl) 
player.getControl("VolumeControl"); 
//if (control != null){ 
// control.setLevel(volumeGauge.getValue()); 
// } 

//player.start(); 
} catch (MediaException mex) { 
display.setCurrent(new Alert("Media Exception", mex.getMessage(), null, 
AlertType.ERROR)); 
} catch (Exception ex){ 
display.setCurrent(new Alert("Exception", ex.getMessage(), null, 
AlertType.ALARM)); 








someone help me pls... 

thanks.






[mobility] Re: playing audio files in J2ME using Netbeans 7.1

allan 02/09/2012

[mobility] Re: playing audio files in J2ME using Netbeans 7.1

allan 02/10/2012

Project Features

About this Project

Mobility was started in November 2009, is owned by dstrupl, and has 37 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close