我一直在寻找并尝试约2周,以便能够在我的android应用程序中获得视频播放器。Android Studio中的VideoView问题
我已经尝试了很多解决方案,甚至是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>
这是在MainActivity:
package no.test.videotest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.net.Uri;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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";
Uri vidUri = Uri.parse(vidAddress);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(videoView);
videoView.setMediaController(vidControl);
videoView.start();
}
}
当我上传这对我的手机,我唯一得到的是一个黑色的录像机没有控制,没有视频。
希望有人能告诉我这里有什么问题。 谢谢。
检查清单INTERNET权限 –
我有。 –
Joakim