MediaController is not working properly with MediaPlayer

by manoj » Mon, 22 Jun 2009 14:38:02 GMT


Sponsored Links
 i,

I want to enable the MediaController for the MediaPlayer.

For this I have written the code like this:

public class AudioPlayerNew extends Activity implements
MediaPlayerControl,MediaPlayer.OnPreparedListener,MediaPlayer.OnBufferingUpdateListener
{
MediaController mediaController;
MediaPlayer mMediaPlayer;
private String path = "/sdcard/Kaarulo Shikarukelle.mp3";
int percent = 1;
boolean playerState = true;

public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.sdcard_media_view);
mediaController = (MediaController) findViewById
(R.id.MediaController01);
playAudio(path);
mediaController.setAnchorView( findViewById
(R.layout.sdcard_media_view));
mediaController.setMediaPlayer(this);
mediaController.bringToFront();
mediaController.setEnabled(true);
}

private void playAudio(String media)
{
try
{
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(path);
mMediaPlayer.prepare();

mMediaPlayer.setOnSeekCompleteListener(this);

mMediaPlayer.setOnPreparedListener(this);

mMediaPlayer.setOnCompletionListener(this);

mMediaPlayer.setOnErrorListener(this);
}
catch (Exception e)
{
Log.e(TAG, "error: " + e.getMessage(), e);
}

}

@Override
protected void onDestroy() {
super.onDestroy();
// TODO Auto-generated method stub
dismissDialog();
if(null != mMediaPlayer)
{
mMediaPlayer.release();
mMediaPlayer = null;
}


wakeLock.release();
}

@Override
public int getBufferPercentage() {
System.out.println("MediaController.getBufferPercentage()
called!!!");
// TODO Auto-generated method stub
return percent;
}

@Override
public int getCurrentPosition() {
System.out.println("MediaController.getCurrentPosition()
called!!!");
// TODO Auto-generated method stub
return mMediaPlayer.getCurrentPosition();
}

@Override
public int getDuration() {
System.out.println("MediaController.getDuration() called!!!");
// TODO Auto-generated method stub
return mMediaPlayer.getDuration();
}

@Override
public boolean isPlaying()
{
//System.out.println("MediaController.isPlaying() called!!!");
// TODO Auto-generated method stub
return playerState;
}

@Override
public void pause()
{
//System.out.println("MediaController.pause() called!!!");
// TODO Auto-generated method stub
if(null != mMediaPlayer)
{
mMediaPlayer.pause();



MediaController is not working properly with MediaPlayer

by manoj » Mon, 22 Jun 2009 17:26:46 GMT


 i, why can't my seek bar (with time) is not updating according to
mediaplayer time.

Can any one please help me.

Thanks,
Manoj.

On Jun 22, 11:37am, manoj <manojkumar.m...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


MediaController is not working properly with MediaPlayer

by manoj » Mon, 22 Jun 2009 19:48:22 GMT


 inally, I solved it!!!

On Jun 22, 2:26pm, manoj <manojkumar.m...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



MediaController is not working properly with MediaPlayer

by plun » Mon, 27 Jul 2009 06:45:59 GMT


 i Manoj,

I'm having trouble with this too. How did you get it working?
(The Mediacontroller won't display on the Mediaplayer)

On Jun 22, 4:48am, manoj <manojkumar.m...@gmail.com> wrote:

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Why corsor need to call setNotificationUri when query from content provider?

In the sample code of android developer
http://developer.android.com/reference/android/content/ContentProvider.html

When query the content provider, the cursor in query () call
setNotificationUri(getContext().getContentResolver(), uri).

But the query is a read-data action, it doesn't need to notify uri
because the database can't update when being read. is there any
propose to avoid some problem adding setNotificationUri in the query
function of content provider?
--~--~---------~--~----~------------~-------~--~----~

2. Add some color to your debugging :)

A few weeks ago I was really fighting with Android logcat debugging
stream.  It dumps out tons of useful information, but it's easy to get
lost in the flood of text.

So I whipped up a quick Python script that reformats the logcat output
into a colorful stream that is much easier to visually follow:

http://www.jsharkey.org/blog/2009/04/22/modifying-the-android-logcat-stream-for-full-color-debugging/

The source is released under an Apache 2.0 license.  Hopefully this
brightens your debugging day.  :)
--~--~---------~--~----~------------~-------~--~----~

3. Why the service is always to restart even if force to kill it?

4. SMSReceiver example throws exception

5. Capturing HEADSET_PLUG (android.intent.action.HEADSET_PLUG)

6. coarse grained vs fine grained location -- when to use?

7. Does android emulator support alsa(not oss)?