[英]I am trying to put a video(mp4) in the app but it is not playing
package com.example.video_app;
import androidx.appcompat.app.AppCompatActivity;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
Button clk;
VideoView Videov;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
clk=(Button)findViewById(R.id.button);
Videov=(VideoView)findViewById(R.id.videoView);
}
public void videoPlay(View v){
String videoPath="android.resource:// com.example.video_app/"+R.raw.sv;//video path
Uri uri= Uri.parse(videoPath);
Videov.setVideoURI(uri);
Videov.start();//start
}
}
I am new to android studio trying to build a simple app of video playing but the video is not playing cant get where the problem is.The video is not playing on emulator nor on my phone.我是 android studio 的新手,试图构建一个简单的视频播放应用程序,但视频没有播放,无法找到问题所在。视频没有在模拟器上播放,也没有在我的手机上播放。 i have tried all the codes mentioned in stackoverflow but could not find any solution... help to resolve this problem
我已经尝试了stackoverflow中提到的所有代码,但找不到任何解决方案......帮助解决这个问题
Check out OnPreparedListener .查看OnPreparedListener 。 Call start() from inside that event, since then the file will be ready to be played.
从该事件内部调用 start(),从那时起文件就可以播放了。
You haven't called videoPlay()
method from any of the method, Call videoPlay()
method from onCreate()
after findViewById()
of video view.您还没有叫
videoPlay()
从任何一个方法,调用的方法videoPlay()
自法onCreate()
后findViewById()
视频的看法。
and remove View v
from videoPlay()
method,i think it's useless.并从
videoPlay()
方法中删除View v
,我认为它没用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.