0

I have an android app with a personalized VideoView which allows two people to stream and sync together. So each person's pause/play action will make the other's player pause/play two.

so i need to distinguish if the start()/pause() function are from user touch or from sync. So I'm thinking of setting a boolean value when user touch the play/pause button on MediaController, a boolean value will be set, But I don't know how to detect if the play button on MediaContoller is triggered.

Here's my VideoView class code:

public class MyVideoView extends VideoView {

private VideoActionListener listener;


public MyVideoView(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
}

public MyVideoView(Context context, AttributeSet attrs){
    super(context, attrs);
}

public MyVideoView(Context context, AttributeSet attrs, int defStyle){
    super(context, attrs, defStyle);
}

public void setOnVideoActionListener(VideoActionListener l){
    listener = l;
}

@Override
public void start(){
    if(listener != null){
        listener.onPlay(this.getCurrentPosition());
        super.start();
    }else{
        super.start();
    }

}

@Override
public void pause(){
    super.pause();
    if(listener != null){   
        listener.onPause(this.getCurrentPosition());
    }
}

@Override
public void seekTo(int msec){       
    if(listener!= null){
        listener.onSeek(msec);
        super.seekTo(msec);
    }else{
        super.seekTo(msec);
    }
}


interface VideoActionListener{
    void onPlay(int msec);
    void onPause(int msec);
    void onSeek(int msec);
}


}

And here, in my main activity, I use the VideoView and MediaController:

MyVideoView video;
MyController controller = new MyController(mContext);
video = (MyVideoView)rootView.findViewById(R.id.video);
video.setBackgroundColor(Color.TRANSPARENT);
video.setMediaController(controller);

private class MyController extends MediaController {

    public MyController(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public boolean onTouchEvent(MotionEvent event) {
        Toast.makeText(context, "Controller touch event activated",
                Toast.LENGTH_SHORT).show();
        return true;
        // return super.onTouchEvent(event);

    }

    public boolean onTrackballEvent(MotionEvent event) {
        Toast.makeText(context, "Trackball event activated",
                Toast.LENGTH_SHORT).show();
        return super.onTouchEvent(event);
    }

}  

So, how should I detect when play button in the MediaController is pressed?

Solorchid
  • 215
  • 5
  • 18

1 Answers1

-2

I think you almost make it. Just call setOnVideoActionListener.

MyController controller = new MyController(mContext);
video = (MyVideoView)rootView.findViewById(R.id.video);
video.setBackgroundColor(Color.TRANSPARENT);
video.setMediaController(controller);
video.setOnVideoActionListener (new VideoActionListener() {
...
}
);

Or you can go to here

Community
  • 1
  • 1