开发者

Open video with html5 from assets

I have an app that has HTML and mp4 files. I play these mp4 video files with the <video> tag in the HTML code. I can do it successfully only when the mp4 files are in the sdcard, but when I add the mp4 files to the assets or rest folder the videos can not play. I read all videos in the assets folder (*.mp4) and copy these files to:

/data/data/packaganame/

My code to copy from assets to the "/data/data/packaganame/" folder is:

InputStream isVideo = null;
isVideo = getApplicationContext().getAssets().open("video.mp4");
File fl = new File("/data/data/packaganame/videoout.mp4");
bufEcrivain = new BufferedOu开发者_StackOverflow社区tputStream((new FileOutputStream(fl)));
VideoReader = new BufferedInputStream(isVideo);
byte[] buff = new byte[32 * 1024];
int len;
while( (len = VideoReader.read(buff)) > 0 ){
    bufEcrivain.write(buff,0,len);
}
bufEcrivain.flush();
bufEcrivain.close();

I execute this code for each video, and I don't get any exception. But when I try play the video, I get: "can not play video".

My HTML code is correct because it works fine when the <video> tag read from sdcard:

<video onclick="this.play();" 
       width="308" height="288" 
       autobuffer="autobuffer" controls="controls"
       tabindex="0">
  <source src="videoout.mp4">
</video>

My videos and my HTML files are in the same directory.

Any ideas please?


try copying mp4 from resources like this:

android.content.res.Resources isVideo = somename.mContext.getResources();

with:

InputStream VideoReader = isVideo .openRawResource(R.raw.resources);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜