🗞️ 0. 简介
🤗:乌拉,无去扎, 无去扎,于无去扎!老妈子整天口头吊的学习学习再学习,我耳朵都生茧子,她就会这一句,你们也来吭两句口号,吊俄罗斯辣妹也可以噢。现在来到第三期,让我们一起学习——大哇里期,于无去扎,咩兮加。
😵:这位同学,现在是电脑课。涅如私基(不是俄语课)。
😁:是的,是的,GStreamer 辅导三,应该上影像了。
👶 1. 筑基
🧑:开启辅导三,首先是要能跑。如果你的 app 现在跑不动,对不起,你继续回去筑基,把一二看一遍。欲练神功,必先 X X。(🤨:这小子又再 Y Y 什么。)
瞧,连模拟器都能跑。👧:这画面花花的,好丑噢…
👽 2. 翻译成 Kotlin
ctrl+alt+shift+k,跟着 Yes。
还有在 static 方程加 @JvmStatic。
这次,我加点私货,就是自己的 log 啦。
从其它项目爬过来,放在 common 里面。
接着,帮 Java 放水,练练手。
参考:
class Tutorial3 : Activity(), SurfaceHolder.Callback {
// JNI
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 external fun nativeSurfaceInit(surface: Any)
private external fun nativeSurfaceFinalize()
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
// UI
val play:ImageButton by lazy {
findViewById(R.id.button_play) }
val pause:ImageButton by lazy {
findViewById(R.id.button_stop) }
val sv:SurfaceView by lazy {
findViewById(R.id.surface_video) }
val tvmsg:TextView by lazy {
findViewById(R.id.textview_message) }
// 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
}
// layout
setContentView(R.layout.main)
// buttons
play.setOnClickListener {
is_playing_desired = true
nativePlay()
}
pause.setOnClickListener {
is_playing_desired = false
nativePause()
}