How to play video in VideoView?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 16:19:45

Try to run app in Device , Video may not run in Emulator...

TouchBoarder

see my answere here in the example code provided. If video is not playing try to re-encode it with a program like Handbrake and try again. Info on supported video formats: Android Supported Media Formats

Mehdi

Try to add permission to connect to internet !

uses-permission android:name="android.permission.INTERNET"
    public void playVideo() {
            videoView = findViewById(R.id.vid);
 videoView.setVideoPath("rtsp://v7.cache4.c.youtube.com/CiILENy73wIaGQl25yDUbxNXTRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp")
            videoView.start();
        }

Just call this function in your onCreate() method

after eight

The answer to this problem may be in this post:

Returning false or not having an OnErrorListener at all will cause the OnCompletionListener to be called.

So return true instead of false from the function and no error will be shown, i.e.

video.setOnErrorListener(new OnErrorListener() {

    @Override
    public boolean onError(MediaPlayer mp, int what, int extra) {
        Log.d("video", "setOnErrorListener ");
        return true;
    }
});

May be the url is not correct. Try to play that stream using vlc player. If it is played then we can look into other possible reason

Ok first thing you wanna do is clean up your layout, this is your first problem:

unmesh it first and make the problem viewable:

You should have caught the error which is missing your closing cap after center", just add a ">" ... and that's it. Clean the project and you should see rtsp video. And your Internet Permission as previously stated.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!