4

I want to play video in VideoView. When I try to do that I got the following error:

Here is my source code:

package com.video.listitem;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

public class PlayVideo extends Activity {

     VideoView mVideoView;
     MediaController mc;
     String videourl;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.videoplay);

        try {
             mVideoView = (VideoView) findViewById(R.id.videoview);
             String videourl = "rtsp://v7.cache4.c.youtube.com/CiILENy73wIaGQl25yDUbxNXTRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
             mc = new MediaController(this);
             mVideoView.setMediaController(mc);
             mVideoView.requestFocus();
             mVideoView.setVideoURI(Uri.parse(videourl));
             mc.show();
             mVideoView.start();
         } catch (Exception e) {
         //TODO: handle exception
         }  
    }
}

Here is my XML File:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="none"
    android:gravity="center">

    <VideoView
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:id="@+id/videoview" />

</LinearLayout>
Mario Kutlev
  • 4,897
  • 7
  • 44
  • 62
  • can you post your error log.. – Piyush Oct 10 '11 at 09:32
  • i got like this: 10-10 18:16:14.253: ERROR/PlayerDriver(31): Command PLAYER_PREPARE completed with an error or info PVMFFailure 10-10 18:16:14.253: ERROR/MediaPlayer(5161): error (1, -1) 10-10 18:16:14.263: ERROR/MediaPlayer(5161): Error (1,-1) 10-10 18:16:14.263: DEBUG/VideoView(5161): Error: 1,-1 –  Oct 10 '11 at 12:49
  • you have include internet permission in your manifest? – Piyush Oct 11 '11 at 03:42
  • yes..i done that but still i am facing problem –  Oct 11 '11 at 04:45
  • Please post the solution, I am facing the same problem. Thanks – PiyushMishra Dec 10 '12 at 05:42
  • i have also check this , but facing same problem :( please post the solution – Vaishali Sutariya Aug 08 '14 at 04:00
  • Possible duplicate of [Play video from url in VideoView \[Android\]](https://stackoverflow.com/questions/40433248/play-video-from-url-in-videoview-android) – Anchit Sep 09 '18 at 16:07

7 Answers7

3

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

Richa
  • 3,165
  • 1
  • 22
  • 26
1

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

Community
  • 1
  • 1
TouchBoarder
  • 6,422
  • 2
  • 52
  • 60
1

Try to add permission to connect to internet !

uses-permission android:name="android.permission.INTERNET"
duggu
  • 37,851
  • 12
  • 116
  • 113
Mehdi
  • 11
  • 1
0

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;
    }
});
scopchanov
  • 7,966
  • 10
  • 40
  • 68
0
    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

Anchit
  • 171
  • 1
  • 11
-3

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

bheema
  • 323
  • 1
  • 5
  • 9
-3

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.

KaSiris
  • 407
  • 3
  • 13