我尝试通过将视频文件包含到Raw文件夹中以两种方式导入视频,而其他方式则直接调用链接
import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
public class HomeVideo extends Activity{
private VideoView videoView;
String extStorageDirectory;
private String current;
private VideoView mVideoView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set the view to our layout file
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.main);
// Video view: to view our video
String path ="http://commonsware.com/misc/test2.3gp";
VideoView video = (VideoView) findViewById(R.id.video);
Uri uri = Uri.parse("android.resource://comm.fib.work/"+R.raw.test2);
//Uri uri=Uri.parse(path);
video.setVideoURI(uri);
video.start();
}
}
在错误日志中显示
05-15 13:54:14.981:D / MediaPlayer(586):getMetadata 05-15 13:57:57.711:D / MediaPlayer(623):getMetadata
我在清单中包含了权限
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
我找不到遗漏的东西。
答案 0 :(得分:0)
Uri.parse("android.resource://com.yourproject/raw/videofile")
对我来说100%有效 希望它有所帮助: