How to get access to MediaController progressbar?

  • Replies:3
  • OpenNot stickiedUnanswered
  • Forum posts: 4

May 16, 2012 5:25:38 PM via Website

I currently have a mediacontroller that I am using to control a video in a videoview. I am trying to get access to the seekbar/progressbar and am having no luck. I found somethign on google that I thought would work, and it does in fact seem to return back an object, but when I try to assign my own listener to the click event or even just set the visibility of the seekbar to invisible, it doesnt do anything. Any ideas as to what I am doing wrong?

1int topContainerId = getResources().getIdentifier("mediacontroller_progress", "id", "android");
2
3SeekBar seekbar = (SeekBar) mMediaCont.findViewById(topContainerId);
4
5seekbar.setOnClickListener(new OnClickListener(){
6
7 @Override
8 public void onClick(View v) {
9 Log.d("In slider onclick", "WE HAVE LIFT OFF");
10 }
11});
  • Forum posts: 775

May 17, 2012 4:29:42 AM via Website

You need to set the OnClickListener for the MediaController. MediaController has it's own onTouchEvent you can override. It also inherits android.view.View, which has the OnClickListener.

To add the MediaController to your video view call,

myVideoView.setMediaController(myMediaController);

then set an OnClickListener for the media controller:

myMediaController.setOnClickListener (new OnClickListener () {
@Override
public void onClick(View v) {
Log.d("In slider onclick", "WE HAVE LIFT OFF");
}
});
  • Forum posts: 4

May 17, 2012 3:49:47 PM via Website

Thanks for the help Jeremiah. I tried what you had suggested and it still isnt working. I hate to paste a lot of code, but I have done so below in hopes that you may see something I am doing incorrectly with my assignment of the media controller or something. From all I have seen online, this should be working and Im wondering if maybe all these issues are due to something I just happened to not grasp in putting this together.

1public class VideoViewDemo extends Activity implements SurfaceHolder.Callback{
2 private static final String TAG = "VideoViewDemo";
3
4 private CustomVideoView mVideoView;
5 private EditText mPath;
6 private EditText mMessageText;
7 private String current;
8 private MediaController mMediaCont;
9
10 @Override
11 public void onCreate(Bundle icicle) {
12 super.onCreate(icicle);
13 setContentView(R.layout.main);
14 mVideoView = (CustomVideoView) findViewById(R.id.custom_videoview);
15 mVideoView.setVideoViewListener(new CustomVideoView.VideoViewListener() {
16
17 @Override
18 public void onPlay() {
19 System.out.println("Play!");
20 }
21
22 @Override
23 public void onPause() {
24 System.out.println("Pause!");
25 }
26
27 @Override
28 public void onSeekTo(int msec){
29 System.out.println("Seek!");
30 }
31 });
32
33 mMediaCont = new MediaController(this);
34 mMediaCont.setPadding(0, 0, 0, 100);
35 mVideoView.setMediaController(mMediaCont);
36 mMediaCont.setAnchorView(mVideoView);
37 mVideoView.setOnCompletionListener(new OnCompletionListener() {
38 @Override
39 public void onCompletion(MediaPlayer mp) {
40 sendStopBeacon();
41 Toast.makeText(getApplicationContext(), "Video completed", Toast.LENGTH_LONG).show();
42 }
43 });
44
45 mMediaCont.setOnClickListener(new OnClickListener(){
46
47 @Override
48 public void onClick(View v) {
49 // TODO Auto-generated method stub
50 Log.d("In slider onclick", "WE HAVE LIFT OFF");
51 }});
52
53 mMessageText = (EditText) findViewById(R.id.MessageText);
54 mMessageText.setMovementMethod(new ScrollingMovementMethod());
55
56 mPath = (EditText) findViewById(R.id.path);
57
58 runOnUiThread(new Runnable(){
59 public void run() {
60 playVideo();
61 mMessageText.requestFocus();
62 }
63 });
64 }
65
66 @Override
67 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
68 }
69
70 @Override
71 public void surfaceCreated(SurfaceHolder holder) {
72 mMediaCont.show();
73 }
74
75 @Override
76 public void surfaceDestroyed(SurfaceHolder holder) {
77 }
78}
  • Forum posts: 775

May 18, 2012 12:29:45 AM via Website

Try implementing MediaPlayerControl, which will let you override the OnTouchEvent for MediaPlayerControl. It is a montionEvent instead of a click event. If you need to get clicks instead of touches, you can use the MotionEvent supplied by the onTouchEvent to tell if the user has touched down, or up and interpret if its a click with that.

1public class VideoViewDemo extends Activity implements SurfaceHolder.Callback, MediaPlayerControl {
2 private static final String TAG = "VideoViewDemo";
3
4 private CustomVideoView mVideoView;
5 private EditText mPath;
6 private EditText mMessageText;
7 private String current;
8 private MediaController mMediaCont;
9
10 @Override
11 public void onCreate(Bundle icicle) {
12 super.onCreate(icicle);
13 setContentView(R.layout.main);
14 mVideoView = (CustomVideoView) findViewById(R.id.custom_videoview);
15 mVideoView.setVideoViewListener(new CustomVideoView.VideoViewListener() {
16
17 @Override
18 public void onPlay() {
19 System.out.println("Play!");
20 }
21
22 @Override
23 public void onPause() {
24 System.out.println("Pause!");
25 }
26
27 @Override
28 public void onSeekTo(int msec){
29 System.out.println("Seek!");
30 }
31 });
32
33 mMediaCont = new MediaController(this);
34 mMediaCont.setPadding(0, 0, 0, 100);
35 mVideoView.setMediaController(mMediaCont);
36 mMediaCont.setAnchorView(mVideoView);
37 mVideoView.setOnCompletionListener(new OnCompletionListener() {
38 @Override
39 public void onCompletion(MediaPlayer mp) {
40 sendStopBeacon();
41 Toast.makeText(getApplicationContext(), "Video completed", Toast.LENGTH_LONG).show();
42 }
43 });
44
53 mMessageText = (EditText) findViewById(R.id.MessageText);
54 mMessageText.setMovementMethod(new ScrollingMovementMethod());
55
56 mPath = (EditText) findViewById(R.id.path);
57
58 runOnUiThread(new Runnable(){
59 public void run() {
60 playVideo();
61 mMessageText.requestFocus();
62 }
63 });
64 }
65
66 @Override
67 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
68 }
69
70 @Override
71 public void surfaceCreated(SurfaceHolder holder) {
72 mMediaCont.show();
73 }
74
75 @Override
76 public void surfaceDestroyed(SurfaceHolder holder) {
77 }

@Override
public boolean onTouchEvent(MotionEvent me) {
// TODO Auto-generated method stub
mMediaController.show();
Log.d("In slider onclick", "WE HAVE LIFT OFF");

return false;
}
78}