hello all
we have develop a j2me music player. that play a music from RMS having path save in input steam. and play sound file one by one. but we have some problem to pause and stop music player while it's in running mode. i found the problem that i canniot get scope of player object in key press event. i have put my code here
pls any one find an help me out.
Code:public void player(int numoffile) { try { fc12 = (FileConnection) Connector.open("file://" + musicurl[numoffile],Connector.READ_WRITE); is12 = fc12.openInputStream(); music = Manager.createPlayer(is12, "audio/x-wav"); //music.addPlayerListener(this); music.realize(); music.prefetch(); music.start(); System.out.println("inside player "+music); } catch (Exception e) { e.printStackTrace(); } } public void playerUpdate(Player player, String event, Object data) { if (event.equals(PlayerListener.END_OF_MEDIA)) { try { if(incPlay < musicurl.length-1) { System.out.println("player call again"); incPlay += 1; player(incPlay); } } catch (Exception e) { e.printStackTrace(); } } } public void playMusic(){ try{ if(isFirstTime){ music.start(); isFirstTime = false; }else{ System.out.println("Time:"+time); music.setMediaTime(time); music.start(); } }catch(Exception e){ System.out.println("in play:"+e); } } public void pauseMusic(){ try{ time = music.getMediaTime(); music.stop(); }catch(Exception e){ System.out.println("in pause:"+e); } } protected void keyPressed(int keyCode) { switch (keyCode) { case -5: System.out.println("currentPlayer is "+music); System.out.println("pause"); System.out.println("currentPlayer is "+music); if (music !=null) { pauseMusic(); } break; } else { System.out.println("play"); if (music !=null) { playMusic(); } break; } }

Reply With Quote

