I want to play a video in my Android app, and used the following code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showVideo();
}
private void showVideo()
{
VideoView vd = (VideoView)findViewById(R.id.videoview);
Uri uri = Uri.parse("android.resource://package/"+R.raw.movie);
MediaController mc = new MediaController(this);
vd.setMediaController(mc);
vd.setVideoURI(uri);
vd.start();
}
Using this code, I am getting an error that the video can not be played.
Just a thought...should your URI really have "package" in the path? shouldn't you replace that with your actual application package: "com.whatever.something"?
您想要getPackageName,或手动提供它以使其正常工作:
Uri uri=Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.movie);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.