[Java for Android App Development] ThayarM:
I have enabled the media controller in the onprepared listener . But i cannot view the media controller when run.

But the audio song is playing.

Please tell me where i did the mistakes.Here is my code:

public class Tabact1 extends Activity implements OnPreparedListener,MediaPlayerControl{

MediaPlayer mediaPlayer;

MediaController controller;

private Handler handler=new Handler();

private String audioFile;

[MENTION=439709]override[/MENTION]

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_tabact1);

mediaPlayer=new MediaPlayer();

mediaPlayer.setOnPreparedListener(this);

controller=new MediaController(this);

try {

mediaPlayer.setDataSource(getApplicationContext(), Uri.parse("android.resource://com.example.tablayout/" + R.raw.sample));

} catch (IllegalArgumentException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SecurityException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalStateException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

try {

mediaPlayer.prepare();

} catch (IllegalStateException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

mediaPlayer.start();

}

[MENTION=439709]override[/MENTION]

public void onPrepared(MediaPlayer mp) {

// TODO Auto-generated method stub

controller.setMediaPlayer(this);

handler.post(new Runnable() {

[MENTION=439709]override[/MENTION]

public void run() {

// TODO Auto-generated method stub

controller.setEnabled(true);

controller.show();

}

});

}

[MENTION=439709]override[/MENTION]

protected void onStop() {

// TODO Auto-generated method stub

super.onStop();

controller.hide();

mediaPlayer.stop();

mediaPlayer.release();

}

[MENTION=439709]override[/MENTION]

public boolean onTouchEvent(MotionEvent event) {

// TODO Auto-generated method stub

controller.show();

return false;

}

[MENTION=439709]override[/MENTION]

public boolean canPause() {

// TODO Auto-generated method stub

return true;

}

[MENTION=439709]override[/MENTION]

public boolean canSeekBackward() {

// TODO Auto-generated method stub

return true;

}

[MENTION=439709]override[/MENTION]

public boolean canSeekForward() {

// TODO Auto-generated method stub

return true;

}

[MENTION=439709]override[/MENTION]

public int getBufferPercentage() {

// TODO Auto-generated method stub

return 0;

}

[MENTION=439709]override[/MENTION]

public int getCurrentPosition() {

// TODO Auto-generated method stub

return mediaPlayer.getCurrentPosition();

}

[MENTION=439709]override[/MENTION]

public int getDuration() {

// TODO Auto-generated method stub

return mediaPlayer.getDuration();

}

[MENTION=439709]override[/MENTION]

public boolean isPlaying() {

// TODO Auto-generated method stub

return mediaPlayer.isPlaying();

}

[MENTION=439709]override[/MENTION]

public void pause() {

// TODO Auto-generated method stub

mediaPlayer.pause();

}

[MENTION=439709]override[/MENTION]

public void seekTo(int arg0) {

// TODO Auto-generated method stub

mediaPlayer.seekTo(arg0);

}

[MENTION=439709]override[/MENTION]

public void start() {

// TODO Auto-generated method stub

mediaPlayer.start();

}

}