Created
March 20, 2019 12:11
-
-
Save aaalaniz/b0bc08765dc31265d399bdea5d30a0d6 to your computer and use it in GitHub Desktop.
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.VideoTextureView; | |
/* | |
* VideoTextureView that notifies Listener of the first frame rendered and the first frame after a reset | |
* request. | |
*/ | |
public class CustomVideoTextureView extends VideoTextureView { | |
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