【发布时间】:2018-10-17 10:19:11
【问题描述】:
我是一名 11 岁的编码员,当我尝试运行视频查看代码以便播放视频时,我的手机上出现此错误。 错误是“抱歉,无法播放此视频。”我下载的视频在资源下的原始文件夹中,代码和xml都很好。我使用的视频格式是 mp4。这是我的代码:
package com.example.lenovouser.video;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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 = findViewById(R.id.video_view);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.green_and_yellow_popsicle);
videoView.setVideoURI(uri);
videoView.setMediaController(new MediaController(this));
videoView.start();
}
}
这是我的 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.lenovouser.video.MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
</android.support.constraint.ConstraintLayout>
感谢您的宝贵时间!
【问题讨论】:
-
我更新了我的问题。
标签: java android xml android-studio debugging