JonDal
JonDal

Reputation: 93

Cannot resolve method; possible dependency issue

I've been trying to figure this out for the past 2 hours. I'm using a MediaBrowsterCompat.ConnectionCallback and I want to use the setSupportedMediaController() and getSupportedMediaController() methods, but no matter what i import or implement in gradle they don't show up. I'm referencing code from github and as far as i can tell i have everything I need. still won't work.

The code in question:

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 ) {

        }
    }
}

My gradle:

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

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

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.2.1' compile 'com.android.support:support-v13:24.2.1'

}

I imported their project into ADS and looked where the methods come from, and it's android.support.v4.app.FragmentActivity. I've tried importing every version of that package, still no use.

Upvotes: 2

Views: 474

Answers (2)

Silambarasan
Silambarasan

Reputation: 665

As the accepted answer, you can use like,

set:

MediaControllerCompat.setMediaController(MainActivity.this, mMediaControllerCompat);

get:

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

Upvotes: 0

Amani
Amani

Reputation: 3977

As you can see in the following official link there is no setSupportedMediaController() or getSupportedMediaController() methods in MediaBrowserCompat.ConnectionCallback

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

FragmentActivity.setSupportMediaController() and FragmentActivity.getSupportMediaController() have been removed. Please use the new static MediaControllerCompat.setMediaController() and MediaControllerCompat.getMediaController() methods.

You may use these methods:

MediaControllerCompat.getMediaController(activity)
MediaControllerCompat.setMediaController()

Upvotes: 2

Related Questions