I am trying to make a radio streaming app in Android Studio using MediaPlayer, but when I compile it shows the next error:
uses or overrides a deprecated API. Recompile with -Xlint:deprecation for details.
I searched in Android documentation and I should replace this method for setAudioAttributes, how can I change it?
public class Radio extends Fragment {
Button play_pause;
MediaPlayer mp;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.radio, container, false);
play_pause = (Button) view.findViewById(R.id.btnplay);
try {
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setDataSource("http://198.27.83.65:9962/;stream.mp3");
mp.prepareAsync();
}
catch (Exception e){
Toast.makeText(getContext(),"Error" + e,Toast.LENGTH_SHORT).show();
}
//mp = MediaPlayer.create(this.getContext(), R.raw.radio);
play_pause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mp.isPlaying()) {
mp.pause();
Toast.makeText(getContext(),"Stop",Toast.LENGTH_SHORT).show();
}
else {
mp.start();
Toast.makeText(getContext(),"Start",Toast.LENGTH_SHORT).show();
}
}
});
return view;
}
}