GStreamer 安卓安装辅导二:最最简单的音频播放器——只有紧紧呼唤(原版),附加:尖叫 和 踢踢。

🤖0. 重复操作:辅导一 到 辅导五

下面就轮到辅导二。Build 里面建议什么,就干什么。辅导一改什么,这里就重复操作。

  1. Gradle: GradleExceptionException
  2. 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"
  1. 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'
}
  1. AndroidManifest 备注 targetSdkVersion
    remark
  2. 抄 GStreamer.java:
    copy
    辅导二: 完毕
    😴接着自我催眠:I’m robot. 我是机器人。
    辅导三,重复操作…完毕。
    辅导四,重复操作…完毕。
    辅导五,重复操作…AndroidManifest 少了 URL,不管了,碰到再修。

🐣1. 辅导二干啥?

看看 GStreamer 网主怎么介绍的:

  • 生产线人(😺:喵,我喜欢。)
  • C 线 和 Java 之间的联系
  • 在 C 里面使用 Java 码
  • C/ Java: 我要/我要——分配 CustomData

不管怎样,先把辅导二修好,跑起来再详细看。

(🚁) Java to Kotlin

象辅导一那样,Ctrl+Alt+Shift+K:
toK
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
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值