这是我的代码。首先,我录制了一个音频文件并开始播放。用于播放音频文件
/**
*
* play the recorded audio
*
*/
public void playAudio() {
try {
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse(path);
intent.setDataAndType(data, "audio/mp3");
startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
// TODO: handle exception
}
}
输出调用设备的默认媒体播放器。在这里,我需要在该媒体播放器中显示一张图像来代替专辑图像。
这是我需要的图像:
![enter image description here](https://i.stack.imgur.com/SIqjW.jpg)
默认媒体播放器使用以下代码来检索歌曲的专辑封面。
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
ContentResolver res = context.getContentResolver();
InputStream in = res.openInputStream(uri);
Bitmap artwork = BitmapFactory.decodeStream(in);
其中 album_id 是歌曲的专辑 ID。因此,为了显示专辑封面,默认播放器应该知道专辑 ID 并检查是否存在与该 ID 关联的专辑封面。因此,如果您想展示艺术品,您必须将文件插入 Android 的数据库,然后从那里播放。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)