让我解释清楚:
- 我有一个名为“声音”的文件夹,并且有一些 .ogg 文件可以播放。
- 我使用
Environment.getExternalStorageDirectory().getAbsolutePath() + mySoundsPath;
. - 我从该文件夹中获取了所有列表并将其保存到数组中:
List<String> soundList;
我的问题是:
- 如何调用
soundList
我创建的声音以便它们都可以播放? - 它是否需要解码(如图像,解码为位图)?
对不起我的语法。提前致谢。
让我解释清楚:
Environment.getExternalStorageDirectory().getAbsolutePath() + mySoundsPath;
.List<String> soundList;
我的问题是:
soundList
我创建的声音以便它们都可以播放?对不起我的语法。提前致谢。
使用以下链接作为参考 http://developer.android.com/reference/android/media/MediaPlayer.html
您也可以尝试小代码示例
公共无效播放(字符串路径){count++; 播放文件=路径;
//showNotification();
new NotificationPanel(activity);
if(mediaPlayer!=null && mediaPlayer.isPlaying()){
Log.d("*****begin*****", "playing");
stopPlaying();
Log.d("*****begin*****", "stoping");
} else{
Log.d("*****begin*****", "nothing");
}
Uri myUri1 = Uri.parse(path);
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(activity, myUri1);
} catch (IllegalArgumentException e) {
Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
}
mediaPlayer.start();
}
private void stopPlaying() {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
}