-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #234 from shogo4405/feature/compose-playback
Support jetpack compose module.
- Loading branch information
Showing
12 changed files
with
270 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.haishinkit.app | ||
|
||
import android.util.Log | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.unit.dp | ||
import com.haishinkit.compose.HaishinKitView | ||
import com.haishinkit.compose.rememberConnectionState | ||
import com.haishinkit.compose.rememberStreamState | ||
import com.haishinkit.rtmp.RtmpConnection | ||
|
||
@Composable | ||
fun PlaybackScreen( | ||
command: String, | ||
streamName: String, | ||
modifier: Modifier | ||
) { | ||
val connectionState = rememberConnectionState() | ||
val streamState = rememberStreamState( | ||
context = LocalContext.current, | ||
connectionState = connectionState, | ||
connectionStateChange = { stream, data -> | ||
val code = data["code"].toString() | ||
if (code == RtmpConnection.Code.CONNECT_SUCCESS.rawValue) { | ||
stream.play(streamName) | ||
} | ||
} | ||
) | ||
Box(modifier = modifier) { | ||
HaishinKitView( | ||
streamState = streamState, | ||
modifier = Modifier.fillMaxSize() | ||
) | ||
Button( | ||
modifier = Modifier | ||
.width(100.dp) | ||
.height(50.dp), | ||
onClick = { | ||
Log.w(TAG, "GO LIVE!!") | ||
connectionState.connect(command) | ||
}) { | ||
Text("GO LIVE") | ||
} | ||
} | ||
} | ||
|
||
private const val TAG = "PlaybackScreen" |
82 changes: 12 additions & 70 deletions
82
app/src/main/java/com/haishinkit/app/PlaybackTabFragment.kt
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
plugins { | ||
id 'com.android.library' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
namespace 'com.haishinkit.compose' | ||
compileSdk 34 | ||
|
||
defaultConfig { | ||
minSdk 21 | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles "consumer-rules.pro" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_17 | ||
targetCompatibility JavaVersion.VERSION_17 | ||
} | ||
buildFeatures { | ||
compose true | ||
} | ||
composeOptions { | ||
kotlinCompilerExtensionVersion = "1.5.11" | ||
} | ||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_17 | ||
} | ||
} | ||
|
||
dependencies { | ||
api project(':haishinkit') | ||
implementation platform('androidx.compose:compose-bom:2024.03.00') | ||
implementation 'androidx.compose.foundation:foundation:1.6.4' | ||
implementation 'androidx.core:core-ktx:1.12.0' | ||
implementation 'androidx.appcompat:appcompat:1.6.1' | ||
implementation 'com.google.android.material:material:1.11.0' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
} |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
26 changes: 26 additions & 0 deletions
26
compose/src/main/java/com/haishinkit/compose/ConnectionState.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.haishinkit.compose | ||
|
||
import android.content.Context | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import com.haishinkit.rtmp.RtmpConnection | ||
import com.haishinkit.rtmp.RtmpStream | ||
|
||
@Composable | ||
fun rememberConnectionState(): ConnectionState = remember { ConnectionState() }.apply { | ||
|
||
} | ||
|
||
class ConnectionState { | ||
internal val connection: RtmpConnection by lazy { | ||
RtmpConnection() | ||
} | ||
|
||
fun connect(command: String) { | ||
connection.connect(command) | ||
} | ||
|
||
internal fun createStream(context: Context): RtmpStream { | ||
return RtmpStream(context, connection) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
compose/src/main/java/com/haishinkit/compose/HaishinKitView.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.haishinkit.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.viewinterop.AndroidView | ||
import com.haishinkit.graphics.VideoGravity | ||
import com.haishinkit.view.HkSurfaceView | ||
|
||
@Composable | ||
fun HaishinKitView( | ||
streamState: StreamState, | ||
modifier: Modifier = Modifier, | ||
videoGravity: VideoGravity = VideoGravity.RESIZE_ASPECT | ||
) { | ||
AndroidView( | ||
factory = { | ||
HkSurfaceView(it).apply { | ||
this.videoGravity = videoGravity | ||
attachStream(streamState.stream) | ||
} | ||
}, | ||
modifier = modifier | ||
) | ||
} |
Oops, something went wrong.