0

我想在我的 Android 应用中播放视频,并使用以下代码:

@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();
}

使用此代码,我收到无法播放视频的错误。

4

2 回答 2

1

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"?

于 2012-11-08T00:57:08.863 回答
0

您想要获取PackageName,或手动提供它以使其工作:

Uri uri=Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.movie);        
于 2013-04-26T16:20:47.900 回答