gpt4 book ai didi

java - MediaControllerCompat 和 MediaSessionCompat Android X?

转载 作者:行者123 更新时间:2023-12-04 15:36:44 33 4
gpt4 key购买 nike

我对 MediaControllerCompat 和 MediaSessionCompat 的导入

import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.MediaSessionCompat;

private MediaSessionCompat mMediaSessionCompat;
private MediaControllerCompat.TransportControls mTransportControls;

我最近将我的项目迁移到 Android X,但是这些导入在迁移时没有改变,而是将其添加到我的 gradle 的依赖项中。

implementation 'androidx.legacy:legacy-support-v4:1.0.0'

现在我想知道为什么他们不更改为 Android X,我搜索了 MediaControllerCompat 和 MediaSessionCompat 的 android x 依赖项,但我找不到它们。

最佳答案

在您的 gradle.properties 中,您可以看到 android.enableJetifier=true 当我们在 androidx 中迁移我们的项目时,它会处理所有第三方库,一个属性将处理所有迁移内容。

现在关于你的问题,我在开发 mp3 音频应用程序时使用了这两个类,但在迁移到 Androidx 之后它仍然没有添加任何额外的库。

implementation 'androidx.legacy:legacy-support-v4:1.0.0'

我的类(class):

package com.broadcast.audioplayerkotlin

import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatSeekBar
import android.support.v4.media.session.MediaControllerCompat
import android.support.v4.media.MediaMetadataCompat

import android.widget.SeekBar

import android.support.v4.media.session.PlaybackStateCompat

import android.util.Log


class MediaSeekBar : AppCompatSeekBar {
private val TAG = "MediaSeekBar"
private var mMediaController: MediaControllerCompat? = null
private var mControllerCallback: ControllerCallback? = null
private var mIsTracking = false
private val mOnSeekBarChangeListener = object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {}

override fun onStartTrackingTouch(seekBar: SeekBar) {
mIsTracking = true
}

override fun onStopTrackingTouch(seekBar: SeekBar) {
mMediaController?.transportControls?.seekTo(progress.toLong())
mIsTracking = false
}
}

constructor(ctx: Context) : super(ctx)
constructor(code: Context, attrs: AttributeSet?) : super(code, attrs) {

super.setOnSeekBarChangeListener(mOnSeekBarChangeListener)
}

constructor(code: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(code, attrs) {
}

override fun setOnSeekBarChangeListener(l: SeekBar.OnSeekBarChangeListener) {
// Prohibit adding seek listeners to this subclass.
throw UnsupportedOperationException("Cannot add listeners to a MediaSeekBar")
}

fun setMediaController(mediaController: MediaControllerCompat?) {
if (mediaController != null) {
mControllerCallback = ControllerCallback()
mediaController.registerCallback(mControllerCallback!!)
} else if (mMediaController != null) {
mMediaController!!.unregisterCallback(mControllerCallback!!)
mControllerCallback = null
}
mMediaController = mediaController
}

fun disconnectController() {
if (mMediaController != null) {
mMediaController!!.unregisterCallback(mControllerCallback!!)
mControllerCallback = null
mMediaController = null
}
}

private inner class ControllerCallback : MediaControllerCompat.Callback() {

override fun onSessionDestroyed() {
super.onSessionDestroyed()
}


override fun onPlaybackStateChanged(state: PlaybackStateCompat?) {
super.onPlaybackStateChanged(state)
Log.d(TAG, "onPlaybackStateChanged: CALLED: playback state: " + state!!)

val progress = state?.position?.toInt() ?: 0
setProgress(progress)

}

override fun onMetadataChanged(metadata: MediaMetadataCompat?) {
super.onMetadataChanged(metadata)
}

}
}

Gradle 依赖:

 dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

//RecyclerView
implementation 'com.android.support:recyclerview-v7:28.0.0'


def glideVersion = "4.8.0"
implementation "com.github.bumptech.glide:glide:$glideVersion"
annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"

// ExoPlayer
implementation 'com.google.android.exoplayer:exoplayer:2.8.4' // 2.9.0 has min sdk 26

// Firestore
implementation 'com.google.firebase:firebase-firestore:17.1.2'
}

只是好奇为什么要添加额外的库。

关于java - MediaControllerCompat 和 MediaSessionCompat Android X?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59496145/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com