Java 在内部存储器中打开视频
我使用WS在我的应用程序中下载视频。 之后我想打开下载的视频 问题是,当我想打开视频时,出现以下错误:Java 在内部存储器中打开视频,java,android,android-videoview,loopj,Java,Android,Android Videoview,Loopj,我使用WS在我的应用程序中下载视频。 之后我想打开下载的视频 问题是,当我想打开视频时,出现以下错误: VideoView: Unable to open content: /data/user/0/code.package/files/diapos/1.mp4 java.io.IOException: setDataSource failed. 这是下载功能: MyRestClient.get("/diapos/1", null, new BinaryHttpResponseHandler(
VideoView: Unable to open content: /data/user/0/code.package/files/diapos/1.mp4
java.io.IOException: setDataSource failed.
这是下载功能:
MyRestClient.get("/diapos/1", null, new BinaryHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] binaryData) {
InputStream input = new ByteArrayInputStream(binaryData);
try {
OutputStream output = new FileOutputStream("/diapos/1.mp4");
byte data[] = new byte[4096];
int count;
while ((count = input.read(data)) != -1) {
output.write(data, 0, count);
}
} catch (IOException e) { e.printStackTrace(); }
}
这是我播放视频的方式:
final VideoView video = (VideoView) getActivity().findViewById(R.id.video);
String path = getActivity().getFilesDir().getAbsolutePath() + "/diapos/1.mp4";
video.setVideoURI(Uri.parse(path));
video.start();
也许这不是条好路?还是我保存视频的方式?
我指定视频必须下载到内部存储器中。没有外部存储。您不能这样做。
VideoView
使用的MediaPlayer
对象要求保存文件。内部文件不是。用Uri
传递源代码也是没有用的,比如文件://
:如果是这样,MediaPlayer最终将使用它的方法
也检查同一个参数。我找到了解决方案。它与内部存储器一起工作。 我改用FileAsyncHttpResponseHandler 这是我调用WS的地方:
File file = getApplicationContext().getFileStreamPath("movie.mp4");
Client.TESTVIDEOget(null, new FileAsyncHttpResponseHandler(file) {
@Override public void onSuccess(int statusCode, Header[] headers, File file) {
Log.d("debug", "success : " + file.getAbsolutePath() + "\n size : " + file.length());
}
@Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, File file) {
Log.d("debug", "fail : " + file.getAbsolutePath());
}
});
这是我播放电影的地方:
final VideoView video = (VideoView) getActivity().findViewById(R.id.video);
String path = getActivity().getFilesDir().getAbsolutePath() + "/movie.mp4";
video.setVideoURI(Uri.parse(path));
video.start();
我得等3个小时。对不起,好的。我没有意识到这一点。很抱歉