| Reply | « Previous Thread | Next Thread » |
|
Hi for all
am writing a code for wave media player as the following>>> ** Mainfrm>> package playsound; import javax.microedition.lcdui.*; import java.io.*; import javax.microedition.media.*; /** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2008</p> * <p>Company: </p> * @author not attributable * @version 1.0 */ public class MainFrm extends Form implements CommandListener { PlaysoundMIDlet myPlaysoundMIDlet; Command exitCmd = new Command("Exit", Command.EXIT, 1); Command playWavCmd = new Command("Play WAV", Command.SCREEN, 1); Command playMp3Cmd = new Command("Play MP3", Command.SCREEN, 1); TextField urlTF; public MainFrm(PlaysoundMIDlet myPlaysoundMIDlet) { super("Displayable Title"); this.myPlaysoundMIDlet = myPlaysoundMIDlet; 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(playWavCmd); addCommand(playMp3Cmd); StringItem strItm = new StringItem(null , null); strItm.setText("Hellow Play wav"); append(strItm); urlTF = new TextField( "File Path" , "" , 20 , TextField.ANY); append(urlTF); } public void commandAction(Command command, Displayable displayable) { /** @todo Add command handling code */ if (command == playWavCmd) { WavPlayer myWavPlayer = new WavPlayer(myPlaysoundMIDlet, this); Display.getDisplay(myPlaysoundMIDlet).setCurrent(myWavPlayer); }else if (command == playMp3Cmd) { Alert al = new Alert("Info"); al.setTimeout(1000); al.setString(urlTF.getString()); Display.getDisplay(PlaysoundMIDlet.instance).setCurrent(al);; //Mp3Player myMp3Player = new Mp3Player(myPlaysoundMIDlet, this); //Display.getDisplay(myPlaysoundMIDlet).setCurrent(myMp3Player); }else if (command == exitCmd) { // stop the MIDlet PlaysoundMIDlet.quitApp(); } } } ** Playsound>> package playsound; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2008</p> * <p>Company: </p> * @author not attributable * @version 1.0 */ public class PlaysoundMIDlet extends MIDlet { static PlaysoundMIDlet instance; MainFrm myMainFrm = new MainFrm(this); public PlaysoundMIDlet() { instance = this; } public void startApp() { Display.getDisplay(this).setCurrent(myMainFrm); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public static void quitApp() { instance.destroyApp(true); instance.notifyDestroyed(); instance = null; } } ** Wavplayer >> 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; int currentplayedArray = 0; 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 try { InputStream is = getClass().getResourceAsStream("/res/music.wav"); player = Manager.createPlayer(is, "audio/X-wav"); player.start(); } catch (Exception ex) { ex.printStackTrace(); } } 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); currentplayedArray++; playingThread.run(); } 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 |
|
too long code. seems ok. check audio/x-wav format. case of lettes does matters. u had wrote audio/X-wav .
thanks, jitu_goldie.. KEEP TRYING.. |
| jitu_goldie |
| View Public Profile |
| Find all posts by jitu_goldie |
|
Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
raj_J2ME
Offline
Forum Nokia Champion
|
|
Hi,
Are you asking the issues regarding the player,or just tryin to show the developed player.What we should do for your player, Thanks R a j - The K e r n e l |
|
Quote:
I THINK THE POSTER IS JUST FORGOT ABOUT HIS POSTS AFTER POSTING THE POSTS OR MAY BE HE/SHE IS SO BUSY THAT EVEN HE/SHE DONT HAVE TIME TO REPLY OR APPRECIATE OTHERS FOR HIS/HER HELP. thanks, jitu_goldie.. KEEP TRYING.. |
| jitu_goldie |
| View Public Profile |
| Find all posts by jitu_goldie |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Playing real audio file in Real Player | say2paul | General Symbian C++ | 4 | 2009-05-07 17:43 |
| player freeze when playing from stream | jdesmedt | Mobile Java Media (Graphics & Sounds) | 5 | 2009-02-06 10:32 |
| Player p becomes null after it has started playing audio | sanket2612 | Mobile Java Media (Graphics & Sounds) | 1 | 2008-02-15 20:21 |
| Player does not support playing back other format-audio than default format? | williampresent | Mobile Java Media (Graphics & Sounds) | 0 | 2005-08-09 10:14 |