I am trying to access the methods of the PlaybackParams class in my code but it gives me this error:
Call requires API level 23 (current min is 15): android.media.PlaybackParams#PlaybackParams
The song is playing (not smoothly it kind buffers like in youtube videos) but the set speed isn't increasing the tempo of the song.
Also, the seekTo()
methods works properly but the setSpeed()
method doesn't.
I've been trying to figure out the bug in the code but haven't found my way through yet.
Also, if I delete the whole implementation and the access of PlaybackParams' methods then only the song plays otherwise (as with the provided code) it throws many (-38,0) errors and this error also:
Attempt to perform seekTo in wrong state: mPlayer=0xad7a2460, mCurrentState=0
I know state =0
error means it's trying to start the song before it's loaded but I don't know how to make everything fit in place properly.
Here's my code:
MediaPlayer mySong;
PlaybackParams params = new PlaybackParams();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mySong = MediaPlayer.create(this, R.raw.fixyou);
}
public void musicPlayer (View view) {
mySong.seekTo(20000);
params.setSpeed(0.75f);
mySong.setPlaybackParams(params);
mySong.start();
}
Run the program on an emulator or a real device with API 23 because PlaybackParams class was newly added for API 23 and doesn't exist for lower API's.