| Reply | « Previous Thread | Next Thread » |
|
But when am adding some modifications
on the class of wavplayer to support the buffering concept it doesn't work and an error happen plz anyone try to help me to solve it[/size][/b] package playsound; import javax.microedition.lcdui.*; import java.io.*; import javax.microedition.media.*; import java.util.Vector; public class WavPlayer extends Form implements CommandListener , PlayerListener { Command exitCmd = new Command("Exit", Command.EXIT, 1); Command backCmd = new Command("Back", Command.BACK, 2); Command stopCmd = new Command("Stop", Command.SCREEN, 3); Command startCmd = new Command("Start", Command.SCREEN, 3); PlaysoundMIDlet myPlaysoundMIDlet; Displayable parent; Player player; Thread bufferingThread; Thread playingThread; boolean startPlayingThread; Vector audioByteArrays; public WavPlayer(PlaysoundMIDlet myPlaysoundMIDlet, Displayable parent) { super("Displayable Title"); this.myPlaysoundMIDlet = myPlaysoundMIDlet; this.parent = parent; try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { // Set up this Displayable to listen to command events setCommandListener(this); // add the Exit command addCommand(exitCmd); addCommand(backCmd); addCommand(stopCmd); addCommand(startCmd); play(); } private void play() { //start buffering bufferingThread = new Thread() { public void run() { // thread action goes here try { InputStream is = getClass().getResourceAsStream("/res/music.wav"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); int b; while ( ( (b = is.read()) != -1)) { baout.write(b); if (baout.size() > 1000) { baout.close(); audioByteArrays.addElement(baout.toByteArray()); baout = new ByteArrayOutputStream(); } } is.close(); } catch (IOException ex) { } } }; bufferingThread.start(); //playing playingThread playingThread = new Thread() { public void run() { // thread action goes here startPlayingThread int currentplayedArray = 0; while (audioByteArrays.size() < currentplayedArray) { try { Thread.sleep(500); } catch (InterruptedException ex) { ex.printStackTrace(); } } try { //InputStream is = getClass().getResourceAsStream("/res/music.wav"); ByteArrayInputStream bain = new ByteArrayInputStream( (byte[]) audioByteArrays.elementAt(currentplayedArray) ); player = Manager.createPlayer(bain, "audio/X-wav"); player.start(); } catch (Exception ex) { } } }; playingThread.start(); } public void commandAction(Command command, Displayable displayable) { /** @todo Add command handling code */ if (command == backCmd) { Display.getDisplay(myPlaysoundMIDlet).setCurrent(parent); } else if (command == exitCmd) { try { player.stop(); } catch (MediaException ex) { ex.printStackTrace(); } // stop the MIDlet PlaysoundMIDlet.quitApp(); } else if (command == stopCmd) { try { player.stop(); } catch (MediaException ex) { ex.printStackTrace(); } } else if (command == startCmd) { try { player.start(); } catch (MediaException ex) { ex.printStackTrace(); } } } /** * playerUpdate * * @param player Player * @param string String * @param object Object */ public void playerUpdate(Player player, String event, Object eventData) { if (event == (PlayerListener.VOLUME_CHANGED)) { //VolumeControl vc = (VolumeControl) eventData; //updateDisplay("Volume Changed to: " + vc.getLevel()); //if (vc.getLevel() > 60) { // updateDisplay("Volume higher than 60 is too loud"); // vc.setLevel(60); //} } else if (event == (PlayerListener.STOPPED)) { //updateDisplay("Player paused at: " + (Long) eventData); } else if (event == (PlayerListener.STARTED)) { //updateDisplay("Player started at: " + (Long) eventData); } else if (event == (PlayerListener.END_OF_MEDIA)) { //updateDisplay("Player reached end of loop."); } else if (event == (PlayerListener.CLOSED)) { //updateDisplay("Player closed."); } else if (event == (PlayerListener.ERROR)) { //updateDisplay("Error Message: " + (String) eventData); } } } |
| hamada200700 |
| View Public Profile |
| Find all posts by hamada200700 |
|
explain motive of ur application. what u want to do?
thanks, jitu_goldie.. KEEP TRYING.. |
| jitu_goldie |
| View Public Profile |
| Find all posts by jitu_goldie |
|
Hi,
Can u tell me more about your problem. After i can help u.. Thanks Osam |
|
what kind of buffering you are trying to do? In place of putting all your code if u can specify more about your issue it would be help full.
au revoir Prakash Raman |
| prakash.raman |
| View Public Profile |
| Find all posts by prakash.raman |
|
hi for all
before u g to help me read the thread which called ""is this player playing right"" on the open discussion this 3 parts as wav media player and it run by a nice way Then am add some modifications on the part of wavplyer to support buffering by adding two threads which will be shown in th following and when am run it it doesn't run and appear an error!!! plz hlp me package playsound; import javax.microedition.lcdui.*; import java.io.*; import javax.microedition.media.*; import java.util.Vector; public class WavPlayer extends Form implements CommandListener , PlayerListener { Command exitCmd = new Command("Exit", Command.EXIT, 1); Command backCmd = new Command("Back", Command.BACK, 2); Command stopCmd = new Command("Stop", Command.SCREEN, 3); Command startCmd = new Command("Start", Command.SCREEN, 3); PlaysoundMIDlet myPlaysoundMIDlet; Displayable parent; Player player; Thread bufferingThread; Thread playingThread; boolean startPlayingThread; Vector audioByteArrays; public WavPlayer(PlaysoundMIDlet myPlaysoundMIDlet, Displayable parent) { super("Displayable Title"); this.myPlaysoundMIDlet = myPlaysoundMIDlet; this.parent = parent; try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { // Set up this Displayable to listen to command events setCommandListener(this); // add the Exit command addCommand(exitCmd); addCommand(backCmd); addCommand(stopCmd); addCommand(startCmd); play(); } private void play() { //start buffering bufferingThread = new Thread() { public void run() { // thread action goes here try { InputStream is = getClass().getResourceAsStream("/res/music.wav"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); int b; while ( ( (b = is.read()) != -1)) { baout.write(b); if (baout.size() > 1000) { baout.close(); audioByteArrays.addElement(baout.toByteArray()); baout = new ByteArrayOutputStream(); } } is.close(); } catch (IOException ex) { } } }; bufferingThread.start(); //playing playingThread playingThread = new Thread() { public void run() { // thread action goes here startPlayingThread int currentplayedArray = 0; while (audioByteArrays.size() < currentplayedArray) { try { Thread.sleep(500); } catch (InterruptedException ex) { ex.printStackTrace(); } } try { //InputStream is = getClass().getResourceAsStream("/res/music.wav"); ByteArrayInputStream bain = new ByteArrayInputStream( (byte[]) audioByteArrays.elementAt(currentplayedArray) ); player = Manager.createPlayer(bain, "audio/X-wav"); player.start(); } catch (Exception ex) { } } }; playingThread.start(); } public void commandAction(Command command, Displayable displayable) { /** @todo Add command handling code */ if (command == backCmd) { Display.getDisplay(myPlaysoundMIDlet).setCurrent(parent); } else if (command == exitCmd) { try { player.stop(); } catch (MediaException ex) { ex.printStackTrace(); } // stop the MIDlet PlaysoundMIDlet.quitApp(); } else if (command == stopCmd) { try { player.stop(); } catch (MediaException ex) { ex.printStackTrace(); } } else if (command == startCmd) { try { player.start(); } catch (MediaException ex) { ex.printStackTrace(); } } } /** * playerUpdate * * @param player Player * @param string String * @param object Object */ public void playerUpdate(Player player, String event, Object eventData) { if (event == (PlayerListener.VOLUME_CHANGED)) { //VolumeControl vc = (VolumeControl) eventData; //updateDisplay("Volume Changed to: " + vc.getLevel()); //if (vc.getLevel() > 60) { // updateDisplay("Volume higher than 60 is too loud"); // vc.setLevel(60); //} } else if (event == (PlayerListener.STOPPED)) { //updateDisplay("Player paused at: " + (Long) eventData); } else if (event == (PlayerListener.STARTED)) { //updateDisplay("Player started at: " + (Long) eventData); } else if (event == (PlayerListener.END_OF_MEDIA)) { //updateDisplay("Player reached end of loop."); } else if (event == (PlayerListener.CLOSED)) { //updateDisplay("Player closed."); } else if (event == (PlayerListener.ERROR)) { //updateDisplay("Error Message: " + (String) eventData); } } } |
| hamada200700 |
| View Public Profile |
| Find all posts by hamada200700 |
|
what error is coming with this code..
thanks, jitu_goldie.. KEEP TRYING.. |
| jitu_goldie |
| View Public Profile |
| Find all posts by jitu_goldie |
|
hi,
what is going on when u execute this code.I thing u are getting exception ,try to explain all thinks. |
| sharvan1981 |
| View Public Profile |
| Find all posts by sharvan1981 |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| No audio over bluetooth HFP, but standard media player works (using CMdaAudioPlayerU) | Andrey.Tetyuev | General Symbian C++ | 7 | 2009-08-19 09:30 |
| Problem creating player on N81 | lamiaaMB | Mobile Java Media (Graphics & Sounds) | 6 | 2008-06-24 20:03 |
| Nokia 6630 & 6680 media player | Gordon_Chen | Streaming and Video | 1 | 2007-06-12 19:19 |
| Nokia 3250 Media Player Problems | smash555 | General Discussion | 2 | 2007-02-26 13:03 |
| help with sound media player with animated pictures | larry_ger | Mobile Java General | 0 | 2003-02-25 11:50 |