Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're using the <code>MediaController</code> in combination with a <code>VideoView</code>, it should be relatively easy to extend the latter and add your own listener to it.</p> <p>The custom VideoView would then look something like this in its most basic form:</p> <pre><code>public class CustomVideoView extends VideoView { private PlayPauseListener mListener; public CustomVideoView(Context context) { super(context); } public CustomVideoView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomVideoView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setPlayPauseListener(PlayPauseListener listener) { mListener = listener; } @Override public void pause() { super.pause(); if (mListener != null) { mListener.onPause(); } } @Override public void start() { super.start(); if (mListener != null) { mListener.onPlay(); } } public static interface PlayPauseListener { void onPlay(); void onPause(); } } </code></pre> <p>Using it is identical to using a regular <code>VideoView</code>, with the only difference being that we can now hook up our own listener to it.</p> <pre><code>// Some other code above... CustomVideoView cVideoView = (CustomVideoView) findViewById(R.id.custom_videoview); cVideoView.setPlayPauseListener(new CustomVideoView.PlayPauseListener() { @Override public void onPlay() { System.out.println("Play!"); } @Override public void onPause() { System.out.println("Pause!"); } }); cVideoView.setMediaController(new MediaController(this)); cVideoView.setVideoURI(...); // or cVideoView.setVideoPath(...); // Some other code below... </code></pre> <p>Finally, you may also declare it in your xml layout and inflate it (as shown above) - just make sure your use <code>&lt;package_name&gt;.CustomVideoView</code>. Example:</p> <pre><code>&lt;mh.so.CustomVideoView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/custom_videoview" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload