简体   繁体   English

抱歉,此视频无法在Android VideoView中播放

[英]Sorry this video cannot be played in Android VideoView

I want to play a video in my Android app, and used the following code: 我想在我的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();
}

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? 只是想一想...您的URI是否真的应该在路径中包含“包”? shouldn't you replace that with your actual application package: "com.whatever.something"? 您是否应该用实际的应用程序包“ com.whatever.something”替换它?

您想要getPackageName,或手动提供它以使其正常工作:

Uri uri=Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.movie);        

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM