我正在尝试播放存储在模拟器SD卡中的音乐,但音乐无法播放,下面是我的代码,请告诉我这段代码有什么问题。 我收到了以下错误:
引起:javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚。
谢谢,
play_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG,"Onclick");
mediaPlayer=new MediaPlayer();
String media_path= "sdcard/sample_music.mp3";
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
Uri uri= Uri.parse(media_path);
Log.d(TAG,"Player initiated");
try {
mediaPlayer.setDataSource(getApplicationContext(), uri);
mediaPlayer.prepare();
mediaPlayer.start();
Toast.makeText(getApplicationContext(), "Playback started", Toast.LENGTH_LONG).show();
play_btn.setEnabled(false);
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
play_btn.setEnabled(true);
mediaPlayer.release();
mediaPlayer = null;
Toast.makeText(getApplicationContext(), "Playback finished", Toast.LENGTH_LONG).show();
}
});
}
});