-
-
Save yanwei07/342f048e2cddd5b220d16aea5b775662 to your computer and use it in GitHub Desktop.
VideoView that notifies of a frame rendered after requesting a reset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.os.Handler; | |
import android.os.Looper; | |
import android.util.AttributeSet; | |
import com.twilio.video.I420Frame; | |
import com.twilio.video.VideoView; | |
/* | |
* VideoView that notifies Listener of the first frame rendered and the first frame after a reset | |
* request. | |
*/ | |
public class CustomVideoView extends VideoView { | |
private boolean notifyFrameRendered = false; | |
private Listener listener; | |
private final Handler mainThreadHandler = new Handler(Looper.getMainLooper()); | |
public CustomVideoView(Context context) { | |
super(context); | |
} | |
public CustomVideoView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
@Override | |
public void renderFrame(I420Frame frame) { | |
if (notifyFrameRendered) { | |
notifyFrameRendered = false; | |
mainThreadHandler.post(new Runnable() { | |
@Override | |
public void run() { | |
listener.onFirstFrame(); | |
} | |
}); | |
} | |
super.renderFrame(frame); | |
} | |
/* | |
* Set your listener | |
*/ | |
public void setListener(Listener listener) { | |
this.listener = listener; | |
} | |
/* | |
* Reset the listener so next frame rendered results in callback | |
*/ | |
public void resetListener() { | |
notifyFrameRendered = true; | |
} | |
public interface Listener { | |
void onFirstFrame(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment