在过去的两个小时里,我一直试图解决这个问题。我正在使用MediaBrowsterCompat.ConnectionCallback,我想使用setSupportedMediaController()和getSupportedMediaController()方法,但无论我在gradle中导入或实现什么,它们都不会出现。我正在引用code from github,据我所知,我拥有所需的一切。仍然行不通。
有问题的代码:
class MediaConnectionCallback extends MediaBrowserCompat.ConnectionCallback {
@Override
public void onConnected() {
super.onConnected();
try {
mMediaControllerCompat = new MediaControllerCompat(MainActivity.this, mMediaBrowserCompat.getSessionToken());
mMediaControllerCompat.registerCallback(controllerCallback);
setSupportMediaController(mMediaControllerCompat);
getSupportMediaController().getTransportControls().playFromMediaId(String.valueOf(R.raw.song), null);
} catch( RemoteException e ) {
}
}
}
我的朋友:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.dalcourt.jonathan.testaudio"
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support:support-v13:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout: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'
implementation 'com.android.support:support-v4:28.0.0-rc02'
}
他们的gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.tutsplus.backgroundaudio"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
依赖{compile fileTree(dir:'libs',include:['* .jar'])testCompile'junit:junit:4.12'compile'com.android.support:appcompat-v7:24.2.1'bued'com.android 。支持:支持-V13:24.2.1'
}
我将他们的项目导入ADS并查看方法的来源,它是android.support.v4.app.FragmentActivity。我已经尝试导入该软件包的每个版本,仍然没用。
正如您在以下官方链接中所看到的,setSupportedMediaController()
中没有getSupportedMediaController()
或MediaBrowserCompat.ConnectionCallback
方法
FragmentActivity.setSupportMediaController()和FragmentActivity.getSupportMediaController()已被删除。请使用新的静态MediaControllerCompat.setMediaController()和MediaControllerCompat.getMediaController()方法。
您可以使用以下方法:
MediaControllerCompat.getMediaController(activity)
MediaControllerCompat.setMediaController()