Search code examples
androidmediatabletandroid-4.0-ice-cream-sandwichmediacontroller

Play video with media controller on specific area of an activity


a busy cat
I want to make layout like the attached image but the problem is when I create media controller it doesn't appear below the video player instead it shows on the centre bottom of activity. I've tried to make mediacontroller in xml file but It doesn't work either and also tried this https://stackoverflow.com/a/10315093/1065357 but it also doesn't work. I am using android 4 tablet version.
Thankyou


Solution

  • You can make your custom media control panel, use a bottom panel, add buttons of play,pause,stop etc. add that bottom panel layout where you you want by using layout gravity. On the click on your custom play,pause, stop, forward etc buttons you can call mediaPlayer.play(), mediaPlayer.pause() etc.

    for this purpose, you will be needing to implement SurfaceHolder.callback interface as follow:

    public class VideoViewActivity extends Activity implements SurfaceHolder.Callback 
    {
    
    public boolean canPause() 
    {
    // TODO Auto-generated method stub
    
        Log.e("paused ","called");
        return true;
    }
    
    
    public boolean canSeekBackward() {
        // TODO Auto-generated method stub
        return true;
    }
    
    
    public boolean canSeekForward() {
        // TODO Auto-generated method stub
        return true;
    }
    
    
    public int getBufferPercentage()
    {
        // TODO Auto-generated method stu
        return 0;
    }
    
    
    public int getCurrentPosition() 
    {
        // TODO Auto-generated method stub
    
        return mMediaPlayer.getCurrentPosition();
    
    
    }
    
    
    public int getDuration() 
    {
        // TODO Auto-generated method stub
        return mMediaPlayer.getDuration();
    }
    
    
    public boolean isPlaying() 
        {
        // TODO Auto-generated method stub
        return mMediaPlayer.isPlaying(); 
    }
    
    
    public void pause() {
        // TODO Auto-generated method stub
        mMediaPlayer.pause();
    }
    
    
    public void seekTo(int pos) {
        // TODO Auto-generated method stub
    
        mMediaPlayer.seekTo(pos);
    
    }
    
    
    public void start()
    {
        // TODO Auto-generated method stub
        mMediaPlayer.start();
    }
    

    }

    implementation of this interface will give you access to the media controlling functions(play,pause,seek etc).

    Surface holder can be get as SurfaceHolder holder= surfaceView.getHolder(); and then mediaPlayer.setDisplay(holder)

    you would be declaring your surfaceView tag in your videoViewActivity's layout. surface holder is the component that would be display the video stream of your video.

    i hope this will help.