Мне 11 лет, и я получаю эту ошибку на своем телефоне, когда пытаюсь запустить код просмотра видео, чтобы я мог воспроизвести видео.Ошибка: «Извините, это видео не может быть воспроизведено».Мое видео, которое я скачал, было в папке raw под ресурсами, а код и 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>
Спасибо за ваше время!