Android:How to load files from assets folder?

1.how to use android_asset
file://android_asset/ is a way that allows android apps access assets by a network-based URI. But assets represent neither local nor online files, they are packed into your apk.Put any files in assets folder in a android project and they will be packed into the apk file by the builder.

2.Sample Code:
mVideoView.setVideoPath("file:///android_asset/videos.mp4");
    mVideoView.requestFocus();
    mVideoView.start();
      
String uriPath = "file:///android_asset/videos.mp4";
    Uri uri = Uri.parse(uriPath);
    mVideoView.setVideoURI(uri);
    mVideoView.requestFocus();
    mVideoView.start();
      
String uriPath = "android.resource://yourapplicationpackage/raw/videofilenamewithoutextension";
Uri uri = Uri.parse(uriPath);
video.setVideoURI(uri);
      
mVideoView.setVideoPath("/mnt/sdcard/android_asset/videos.mp4");
      
this.setContentView(R.layout.videoview);       
mVideoView = (VideoView) this.findViewById(R.id.surface_view);       
SurfaceHolder holder = mVideoView.getHolder();
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
MediaPlayer player = new MediaPlayer();
player.setDisplay(holder);       
AssetFileDescriptor afd;
try {
    afd = getAssets().openFd("v.mp4");       
    player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
    player.prepareAsync();
    player.setOnPreparedListener(new OnPreparedListener() {

     @Override
     public void onPrepared(MediaPlayer mp) {
        mp.start();
     }
  });
} catch (Exception e) { e.printStackTrace();}

3.WebView.loadUrl sample code
WebSettings setting=mWebView.getSettings();
setting.setPluginState(PluginState.ON);
setting.setJavaScriptEnabled(true);
        String url="file:///android_asset/test.swf";
mWebView.loadUrl(url);

4.Video Resource
Android Application Development:Using the Asset Folder for Typeface
http://v.youku.com/v_show/id_XMzk5NTI4OTA4.html 
http://www.youtube.com/watch?v=kOJGmVXuuFA1.how

Android:How to load files from assets folder?,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。