Java Android Studio中的视频视图问题

Java Android Studio中的视频视图问题,java,android,xml,android-studio,Java,Android,Xml,Android Studio,我已经搜索和尝试了大约两周,现在能够在我的android应用程序中获得一个视频播放器 我尝试过很多解决方案,甚至是youtube API,但都不起作用。 所以现在我希望有人能看看代码,解释一下我做错了什么,这样我就可以了解这一点:) 这是XML文件: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

我已经搜索和尝试了大约两周,现在能够在我的android应用程序中获得一个视频播放器

我尝试过很多解决方案,甚至是youtube API,但都不起作用。 所以现在我希望有人能看看代码,解释一下我做错了什么,这样我就可以了解这一点:)

这是XML文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="no.test.videotest.MainActivity">


    <VideoView
        android:id="@+id/myVideo"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true" />

</RelativeLayout>
当我把它上传到我的手机上时,我得到的唯一的东西就是一个没有控制和视频的黑色视频播放器

希望有人能告诉我这里出了什么问题。 谢谢。

请尝试以下代码:

VideoView videoView = (VideoView)findViewById(R.id.myVideo);
String vidAddress = "https://ia800201.us.archive.org/22/items/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4";
videoView.setVideoURI(Uri.parse(vidAddress));
videoView.setZOrderOnTop(true);//add this line 
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(videoView);
videoView.setMediaController(vidControl);
videoView.start();

另外,请确保您的地址包含有效的视频

检查清单互联网许可证我拥有该许可证。当我在这里更改Uri vidUri=Uri.parse(vidAddress);with:videoView.setVideoURI(Uri.parse(uriString));然后我是否应该将上面的字符串ViaAddress更改为字符串vidAddress?非常感谢。这非常有效:)现在我可以学习代码并从中学习:)
VideoView videoView = (VideoView)findViewById(R.id.myVideo);
String vidAddress = "https://ia800201.us.archive.org/22/items/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4";
videoView.setVideoURI(Uri.parse(vidAddress));
videoView.setZOrderOnTop(true);//add this line 
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(videoView);
videoView.setMediaController(vidControl);
videoView.start();