How to find a replacement for deprecated method?

noviceUser picture noviceUser · Jul 30, 2017 · Viewed 11.9k times · Source

I am new to Android programming.

I have been following a tutorial on creating a Music Player from this website

The tutorial calls for a setAudioStreamType method from MediaPlayer Class which is deprecated. Which method replaces this deprecated method in particular? And, is there a source where we can find all deprecated methods and its current alternative?

Here is the code I have where there is a warning about a deprecated method:

public void  initMusicPlayer(){
    //set player properties
    player.setWakeMode(getApplicationContext(),
            PowerManager.PARTIAL_WAKE_LOCK);
    player.setAudioStreamType(AudioManager.STREAM_MUSIC);
    player.setOnPreparedListener(this);
    player.setOnCompletionListener(this);
    player.setOnErrorListener(this);
}

Answer

Bob picture Bob · Jul 30, 2017

Use setAudioAttributes(AudioAttributes) instead of setAudioStreamType().

You can see these details in the Android Developer documentation.

https://developer.android.com/reference/android/media/MediaPlayer.html#setAudioStreamType(int)

To follow the latest changes, you can check the Android Developer blog: https://android-developers.googleblog.com/