无法解决方法;可能的依赖性问题

时间:2018-09-07 17:33:44

标签: java android-studio gradle

过去2个小时,我一直在努力解决这个问题。我正在使用MediaBrowsterCompat.ConnectionCallback,并且我想使用setSupportedMediaController()和getSupportedMediaController()方法,但是无论我如何导入或实现,它们都不会显示。我指的是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'
}

他们的成就:

    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'
        }
    }
}

依赖项{     编译fileTree(dir:'libs',包括:['* .jar'])     testCompile'junit:junit:4.12'     编译'com.android.support:appcompat-v7:24.2.1'     编译'com.android.support:support-v13:24.2.1'

}

我将他们的项目导入ADS,并查看了方法的来源,它是android.support.v4.app.FragmentActivity。我尝试导入该软件包的每个版本,仍然没有用。

2 个答案:

答案 0 :(得分:0)

如您在以下官方链接中所见,setSupportedMediaController()中没有getSupportedMediaController()MediaBrowserCompat.ConnectionCallback方法

https://developer.android.com/reference/android/support/v4/media/MediaBrowserCompat.ConnectionCallback

  

FragmentActivity.setSupportMediaController()和   FragmentActivity.getSupportMediaController()已被删除。请   使用新的静态MediaControllerCompat.setMediaController()和   MediaControllerCompat.getMediaController()方法。

您可以使用以下方法:

MediaControllerCompat.getMediaController(activity)
MediaControllerCompat.setMediaController()

答案 1 :(得分:0)

作为接受的答案,您可以使用like

设置:

MediaControllerCompat.setMediaController(MainActivity.this, mMediaControllerCompat);

获取:

MediaControllerCompat.getMediaController(MainActivity.this).getTransportControls().pause();