Android Java 如何使URL转成音频和视频?
url示例:https://12.12.12.12:1223/mms/abc123.jpg
以上示例URL可以转成bitmap,但是如何将表示视频/音频的URL转成视频/音频,
URL示例:
https://12.12.12.12:1223/mms/abc123.mp4 //视频
https://12.12.12.12:1223/mms/abc123.amr //音频
不是为了播放,上面的bitmap是彩信的附件,现在我想还原代表mp4、amr的url成音频或视频,然后添加到彩信的附件发出去
求指点
String URL 转 bitmap 示例:
private Bitmap urlBitmap(String urlString) {
HttpURLConnection urlConnection = null;
BufferedInputStream in = null;
Bitmap bitmap = null;
try {
final URL url = new URL(urlString);
urlConnection = (HttpURLConnection) url.openConnection();
in = new BufferedInputStream(urlConnection.getInputStream(), 8 * 1024);
bitmap = BitmapFactory.decodeStream(in);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
byte[] bytes = bos.toByteArray();
bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
} catch (final IOException e) {
e.printStackTrace();
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
try {
if (in != null) {
in.close();
}
} catch (final IOException e) {
e.printStackTrace();
}
}
return bitmap;
}