Wierd error with button invisibility

All your problems with Audio, Video and Images.

Wierd error with button invisibility

Postby shrikant » Fri Jun 13, 2008 6:09 am

Hey all,
This is a program i wrote to implement play/pause,stop,next,previous,fastforward on a list of three songs.
The two statements highlighted in red towards the end of the program dont get executed at all..
Can anyone plz xpain why it is so?

When play is pressed the button goes invisible and pause button gets visible..
What i wanted was that while playing if i press fastforward, then the pause button shud be removed and play button made visible. But the two statements remain unexecuted and the fast forward begins..
Plz help.. Thanx..
package com.android.google.musicplayer;

import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ListView;

public class MusicPlayer extends Activity {
/** Called when the activity is first created. */
MediaPlayer mp;
int currentSong;
ImageButton PAUSE,PLAY;
int flag=0;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
final int filz[]= {R.raw.rock,R.raw.stone,R.raw.shawn};
final ListView lv = (ListView)this.findViewById(R.id.widget1);
PAUSE=(ImageButton)this.findViewById(R.id.pAuse);
PAUSE.setVisibility(4);
PAUSE.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{ mp.pause();
PAUSE.setVisibility(4);
PLAY.setVisibility(0);
flag=1;
}
});
PLAY=(ImageButton)this.findViewById(R.id.pLay);
PLAY.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{ if(flag==1)
{ mp.start();
flag=0;
}
else
if(flag==2)
{ mp.pause();
mp.start();
flag=0;
}
else{
int x=lv.getSelectedItemPosition();
currentSong = x;
mp = MediaPlayer.create(MusicPlayer.this, filz[x]);
try{mp.prepare();}catch(IOException e){}
mp.start();
}
PAUSE.setVisibility(0);
PLAY.setVisibility(4);

}
});
ImageButton STOP=(ImageButton)this.findViewById(R.id.sTop);
STOP.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{ mp.stop();
PAUSE.setVisibility(4);
PLAY.setVisibility(0);
}
});
ImageButton PREV=(ImageButton)this.findViewById(R.id.pRev);
PREV.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{ mp.stop();
if(currentSong>=1)
{ currentSong=currentSong-1;
mp = MediaPlayer.create(MusicPlayer.this, filz[currentSong]);
try{mp.prepare();}catch(IOException e){}
mp.start();
}
}
});
ImageButton NEXT=(ImageButton)this.findViewById(R.id.nExt);
NEXT.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{ mp.stop();
if(currentSong<=1)
{ currentSong=currentSong+1;
mp = MediaPlayer.create(MusicPlayer.this, filz[currentSong]);
try{mp.prepare();}catch(IOException e){}
mp.start();
}
}
});
ImageButton FFOR=(ImageButton)this.findViewById(R.id.fFor);
FFOR.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{ int curPos,fulDur;
flag=2;
fulDur=mp.getDuration();
PAUSE.setVisibility(4);
PLAY.setVisibility(0);

try {Thread.sleep(2000);}catch(Exception e){}
do{
curPos = mp.getCurrentPosition();
mp.seekTo(curPos+2000);
try{Thread.sleep(1000);}catch(Exception e){}
}while((curPos+2000)<fulDur);

}


});
}
}


PS: i dunno why but the code isnt being indented as it is supposed to be... sorry..
shrikant
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri Jun 13, 2008 5:53 am
Location: India

Top

Postby Jesmiatka » Fri Jun 13, 2008 8:18 am

Use the View constants for that.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. View.INVISIBLE
  2.  
  3. View.GONE
  4.  
  5. View.VISIBLE
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  PAUSE.setVisibility(View.VISIBLE);
  2.  
  3. PLAY.setVisibility(View.GONE);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Postby shrikant » Fri Jun 13, 2008 11:32 am

Hmmm, i tried replacing the constant values by the constant names.. Still not working.. :( :(
shrikant
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri Jun 13, 2008 5:53 am
Location: India

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 13 guests