×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    6

    j2me musci plyaer

    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;
    			}
    }

  2. #2
    Registered User
    Join Date
    Dec 2010
    Posts
    39

    Re: j2me musci plyaer

    Are you still looking for solution or already got it ?

    Anyway, you may need a Canvas class running in the foreground, that can receive keyPress events using which u may control your player functions.

Similar Threads

  1. Text Field Focus Problem with J2me(j2me Polish)
    By pollux.java in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2010-10-20, 06:25
  2. J2ME Polish or LWUIT or what for commercial J2ME software?
    By SebastianM in forum Mobile Java General
    Replies: 10
    Last Post: 2010-08-18, 13:04
  3. How to use J2ME polish code in existing J2ME app.
    By raselbd in forum Mobile Java General
    Replies: 2
    Last Post: 2008-08-26, 14:30
  4. How to sign midlet in j2me using Operator or Manufacturer in j2me
    By bfchaudharimca in forum Mobile Java General
    Replies: 2
    Last Post: 2008-08-15, 15:25
  5. How to use nokia j2me series 60 j2me sdk 2.0
    By scheung3 in forum Mobile Java General
    Replies: 3
    Last Post: 2004-12-19, 15:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×