Skip to content

Commit

Permalink
Bump to Android SDK up 34.
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Jan 2, 2024
1 parent fd0e5c4 commit f30b379
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/src/main/java/com/haishinkit/app/Preference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.haishinkit.app
data class Preference(var rtmpURL: String, var streamName: String) {
companion object {
var shared = Preference(
"rtmp://test:[email protected].9/live",
"rtmp://test:[email protected].3/live",
"live"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ class MediaProjectionSource(
override var utilizable: Boolean = false
) :
VideoSource {

private class Callback : MediaProjection.Callback() {
override fun onCapturedContentVisibilityChanged(isVisible: Boolean) {
super.onCapturedContentVisibilityChanged(isVisible)
Log.d(TAG, "Callback#onCapturedContentVisibilityChanged")
}

override fun onCapturedContentResize(width: Int, height: Int) {
super.onCapturedContentResize(width, height)
Log.d(TAG, "Callback#onCapturedContentResize")
}

override fun onStop() {
super.onStop()
Log.d(TAG, "Callback#onStop")
}
}

/**
* Specifies scale that defines a transformation that resizes an image.
*/
Expand Down Expand Up @@ -124,6 +142,8 @@ class MediaProjectionSource(
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.P)
private var isAvailableRotatesWithContentFlag = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P

private val callback: Callback by lazy { Callback() }

override fun setUp() {
if (utilizable) return
val windowManager =
Expand All @@ -132,6 +152,8 @@ class MediaProjectionSource(
if (isRotatesWithContent) {
orientationEventListener?.enable()
}
// Android 14 must register an callback.
mediaProjection.registerCallback(callback, null)
rotation = windowManager.defaultDisplay.rotation
resolution =
Size((metrics.widthPixels * scale).toInt(), (metrics.heightPixels * scale).toInt())
Expand All @@ -143,6 +165,7 @@ class MediaProjectionSource(
if (isRotatesWithContent) {
orientationEventListener?.disable()
}
mediaProjection.unregisterCallback(callback)
mediaProjection.stop()
super.tearDown()
}
Expand All @@ -167,13 +190,15 @@ class MediaProjectionSource(
/**
* Register a listener to receive notifications about when the MediaProjection changes state.
*/
@Suppress("UNUSED")
fun registerCallback(callback: MediaProjection.Callback, handler: Handler?) {
mediaProjection.registerCallback(callback, handler)
}

/**
* Unregister a MediaProjection listener.
*/
@Suppress("UNUSED")
fun unregisterCallback(callback: MediaProjection.Callback) {
mediaProjection.unregisterCallback(callback)
}
Expand Down

0 comments on commit f30b379

Please sign in to comment.