🤖0. 重复操作:辅导一 到 辅导五
下面就轮到辅导二。Build 里面建议什么,就干什么。辅导一改什么,这里就重复操作。
- Gradle: GradleException 改 Exception
- Gradle: 改 sdkVersion:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
ndkVersion '21.4.7075529'
compileSdkVersion 30
defaultConfig {
applicationId "org.freedesktop.gstreamer.tutorials.tutorial_2"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
- Gradle:改 AndroidX
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.13'
// STD
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
}
- AndroidManifest 备注 targetSdkVersion
- 抄 GStreamer.java:
辅导二: 完毕
😴接着自我催眠:I’m robot. 我是机器人。
辅导三,重复操作…完毕。
辅导四,重复操作…完毕。
辅导五,重复操作…AndroidManifest 少了 URL,不管了,碰到再修。
🐣1. 辅导二干啥?
- 生产线人(😺:喵,我喜欢。)
- C 线 和 Java 之间的联系
- 在 C 里面使用 Java 码
- C/ Java: 我要/我要——分配 CustomData
不管怎样,先把辅导二修好,跑起来再详细看。
…
(🚁) Java to Kotlin
象辅导一那样,Ctrl+Alt+Shift+K:
Yes 啦!
class Tutorial2 : Activity() {
// call C function
private external fun nativeInit() // Initialize native code, build pipeline, etc
private external fun nativeFinalize() // Destroy pipeline and shutdown native code
private external fun nativePlay() // Set pipeline to PLAYING
private external fun nativePause() // Set pipeline to PAUSED
private val native_custom_data // Native code will use this to keep private data
: Long = 0
private var is_playing_desired // Whether the user asked to go to PLAYING
= false
private val play:ImageButton by lazy {
findViewById(R.id.button_play) }
private val pause:ImageButton by lazy {
findViewById(R.id.button_stop) }
// Called when the activity is first created.
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Initialize GStreamer and warn if it fails
try {
GStreamer.init(this)
} catch (e: Exception) {
Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
finish()
return
}
setContentView(R.layout.main)
// buttons
play.setOnClickListener {
is_playing_desired = true
nativePlay()
}
pause.setOnClickListener {
is_playing_desired = false
nativePause()
}
if (savedInstanceState != null) {
is_playing_desired = savedInstanceState.getBoolean("playing")
Log.i("GStreamer", "Activity created. Saved state is playing:$is_playing_desired")
} else {
is_playing_desired = false
Log.i("GStreamer", "Activity created. There is no saved state, playing: false")
}
// Start with disabled buttons, until native code is initialized
play.isEnabled = false
pause.isEnabled = false
nativeInit()
}
override fun onSaveInstanceState(outState: Bundle) {
Log.d("GStreamer", "Saving state, playing:$is_playing_desired")
outState.putBoolean("playing", is_playing_desired)
}
override fun onDestroy() {
nativeFinalize()
super.onDestroy()
}
// Called from native code. This sets the content of the TextView from the UI thread.
private fun setMessage(message: String) {
val tv = findViewById<View>(R.id