2017-02-22 14 views
0

WS를 사용하여 내 앱에서 비디오를 다운로드합니다. 다운로드 한 비디오를 열고 싶습니다.내부 저장소에서 비디오 열기

나는이 오류가 비디오를 열고 자 할 때 문제가 :

:

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(); } 
} 

이 내가 비디오를 재생하는 방법입니다

VideoView: Unable to open content: /data/user/0/code.package/files/diapos/1.mp4 
java.io.IOException: setDataSource failed. 

이 다운로드 기능입니다

final VideoView video = (VideoView) getActivity().findViewById(R.id.video); 
String path = getActivity().getFilesDir().getAbsolutePath() + "/diapos/1.mp4"; 
video.setVideoURI(Uri.parse(path)); 
video.start(); 

어쩌면 좋은 길이 아니겠습니까? 아니면 비디오를 저장하는 방법? 비디오를 내부 저장소에 다운로드해야한다고 지정합니다. 외부 저장 장치가 없습니다.

답변

0

해결책을 찾았습니다. 내부 저장소와 함께 작동합니다. 대신 FileAsyncHttpResponseHandler를 사용합니다.

final VideoView video = (VideoView) getActivity().findViewById(R.id.video); 

String path = getActivity().getFilesDir().getAbsolutePath() + "/movie.mp4"; 
video.setVideoURI(Uri.parse(path)); 
video.start(); 
+0

내가 그 3 시간을 기다려야 : 나는 동영상을 재생 곳

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()); } }); 

이것은 :

이 내가 WS 내 전화를 할 수있는 곳입니다. 죄송합니다. –

+0

확인. 나는 그 사실을 몰랐다. 죄송합니다. –

0

이렇게하면 안됩니다. VideoView에서 사용하는 MediaPlayer 개체의 파일은 world-readable이어야합니다. 내부 파일이 아닙니다. 그래서 마지막에 MediaPlayer를이 같은 주장에 또한 setDataSource(String path) 방법

확인 this answer를 사용할 경우 : Urifile:/// 등으로 소스를 전달하는 데에도 쓸모가 없다.