Skip to content

Commit

Permalink
make sure to call through to base implementation from callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedowns committed May 9, 2023
1 parent b5f4417 commit ca99c7c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LeiaTextureRenderer {
}

fun onDrawFrame() {
Log.i(TAG, "onDrawFrame")
//Log.i(TAG, "onDrawFrame")
glViewport(0, 0, size.width, size.height)
logError("glViewport")
glUseProgram(program)
Expand Down Expand Up @@ -163,12 +163,10 @@ class LeiaTextureRenderer {
varying vec2 v_TexCoord;
uniform samplerExternalOES u_Texture;
void main() {
// DEBUG: show red pixels
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
/*gl_FragColor = texture2D(u_Texture, v_TexCoord);
gl_FragColor = texture2D(u_Texture, v_TexCoord);
if (gl_FragColor.a < 0.1) {
discard;
}*/
}
}
"""

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/is/xyz/mpv/MPVActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver, TouchGesturesObse
// LitByLeia
private var mPrevDesiredBacklightModeState = false
private lateinit var sdk: LeiaSDK
// needed so we can forward Pause/Resume
private lateinit var myView: MPVView


// for calls to eventUi() and eventPropertyUi()
Expand Down Expand Up @@ -250,6 +252,9 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver, TouchGesturesObse
binding = PlayerBinding.inflate(layoutInflater)
setContentView(binding.root)

// Leia
myView = findViewById(R.id.player)

// Init controls to be hidden and view fullscreen
hideControls()

Expand Down Expand Up @@ -391,6 +396,9 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver, TouchGesturesObse
}

override fun onPause() {

myView.onPause()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (isInMultiWindowMode || isInPictureInPictureMode) {
Log.v(TAG, "Going into multi-window mode (PiP=$isInPictureInPictureMode)")
Expand Down Expand Up @@ -470,6 +478,8 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver, TouchGesturesObse
}

override fun onResume() {
myView.onResume()

// If we weren't actually in the background (e.g. multi window mode), don't reinitialize stuff
if (activityIsForeground) {
super.onResume()
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/is/xyz/mpv/MPVView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,17 @@ internal class MPVView(context: Context, attrs: AttributeSet) : LeiaSurfaceView(

// pass the change the mainSurface
resize(width, height)

super.surfaceChanged(holder, format, width, height)
}

override fun surfaceCreated(holder: SurfaceHolder) {
Log.w(TAG, "MPVView surfaceCreated. attaching mainSurface to MPV...")
MPVLib.attachSurface(mainSurface) // WAS: holder.surface, changed to write to mainSurface instead

//MPVLib.attachSurface(holder.surface)
// WAS: holder.surface, changed to write to mainSurface instead
MPVLib.attachSurface(mainSurface)

// This forces mpv to render subs/osd/whatever into our surface even if it would ordinarily not
MPVLib.setOptionString("force-window", "yes")

Expand All @@ -412,6 +418,8 @@ internal class MPVView(context: Context, attrs: AttributeSet) : LeiaSurfaceView(
// We disable video output when the context disappears, enable it back
MPVLib.setPropertyString("vo", "gpu")
}

super.surfaceCreated(holder)
}

override fun surfaceDestroyed(holder: SurfaceHolder) {
Expand All @@ -420,6 +428,8 @@ internal class MPVView(context: Context, attrs: AttributeSet) : LeiaSurfaceView(
MPVLib.setPropertyString("vo", "null")
MPVLib.setOptionString("force-window", "no")
MPVLib.detachSurface()

super.surfaceDestroyed(holder)
}

companion object {
Expand Down

0 comments on commit ca99c7c

Please sign in to comment.