인 텐트 (기본 미디어 플레이어)를 통해 원격 비디오 파일을 재생하려고하지만 스트리밍되는 동안 로컬로 저장하려고합니다. 증기가 잘 작동하는 비디오 파일에 저장하려면 다음 코드를 시도하고있다. 이제 파일을 스트리밍하는 즉시 내 의도를 시작하고 싶지만 의도가 시작되면 오류 "Sorry this video can not be played
"이 표시됩니다. 스트리밍이 완료되었을 때 (downloadedSize==totalSize
일 때)이 메소드의 끝으로 인 텐트 코드를 옮기면 잘 작동하지만 동시에 스트리밍되는 동안 재생하려고합니다. 어떤 도움이 필요합니까?비디오 파일을 스트리밍 재생할 수 없습니다.
public String DownloadVideo(String Url, String fileName)
{
String filepath=null;
try {
URL url = new URL(Url);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
File SDCardRoot = Environment.getExternalStorageDirectory();
File file = new File(SDCardRoot,fileName);
if(file.createNewFile())
{
file.createNewFile();
}
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream inputStream = urlConnection.getInputStream();
int totalSize = urlConnection.getContentLength();
int downloadedSize = 0;
byte[] buffer = new byte[1024];
int bufferLength = 0; //used to store a temporary size of the buffer
int counter=0;
while ((bufferLength = inputStream.read(buffer)) > 0) {
fileOutput.write(buffer, 0, bufferLength);
if(downloadedSize>2048)
{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse(file.getPath()),"video/*");
startActivity(i);
}
downloadedSize += bufferLength;
counter++;
}
fileOutput.close();
if(downloadedSize==totalSize) {
filepath=file.getPath();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
filepath=null;
e.printStackTrace();
}
return filepath;
}