1

I am trying to play a video from the device on a VideoView. Here is my code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    vView = (VideoView) findViewById(R.id.videoView);
    mc = new MediaController(this);
    vView.setMediaController(mc);
    String new_emulator_path = "/storage/emulated/0/Download/testvid.mp4";
    Uri uri = Uri.parse(new_emulator_path);
    vView.setVideoURI(uri);
    vView.requestFocus();
    mc.show();
    vView.start();
}

...

<VideoView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/videoView"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:adjustViewBounds="true" />

While using the same code on 5.1 it plays fine, but does not play in 4.3 and below. Following is the log extract:

04-30 00:28:09.141 2293-2293/com.ebook.video D/MediaPlayer: getMetadata
04-30 00:28:09.249 2293-2314/com.ebook.video E/MediaPlayer: error (1, -2147483648)
04-30 00:28:09.257 2293-2293/com.ebook.video E/MediaPlayer: Error (1,-2147483648)
04-30 00:28:09.257 2293-2293/com.ebook.video D/VideoView: Error: 1,-2147483648

I have seen many threads in regard to this error code, but could not comprehend any explanations.

EDIT: I have tried playing videos of different formats - mkv (H264 mpeg-4 AVC) , 3gp (H263), mp4 (H264 mpeg-4 AVC), flv (FLV1). Video with 3gp extension and H263 format plays fine, while others give the error message as mentioned above. Any ideas on how to resolve this ?

jay
  • 1,982
  • 2
  • 24
  • 54

1 Answers1

0

According to Documentation Android not support H265 before android 5.1 So I think you have issue with this. You can use ExoPlayer (Or better way ExoMedia simple wrapper around VideoPlayer & ExoPlayer).

BTW use following piece of code may helps you :

VideoView videoView = (VideoView) findViewById(R.id.videoView1);
videoView.setVideoPath(YOUR_LOCAL_FILE_PATH);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener()  {
         @Override
         public void onPrepared(MediaPlayer mp) {
                    Log.i(TAG,"Hoooray");
                 }
         });

videoView.start();

As I found out from your code you want to display video in emulator so first see this related post.

Community
  • 1
  • 1
Amir
  • 16,067
  • 10
  • 80
  • 119
  • Encoding format is H264 for most of the videos I tried to play in 4.3 sdk. According to the documentation H.264 AVC is available since Android 3+ itself. Please correct me if I'm wrong in my interpretation. – jay Apr 30 '16 at 09:09
  • @AMRUTHAKALIVARAPU You're right. Can you provide more log ? Also test Mp4 video from following uri , I test it on VideoView and works fine. http://www.sample-videos.com/ – Amir Apr 30 '16 at 10:58
  • I have tested for mp4 vids from the link you've mentioned and I still get the same error. – jay May 05 '16 at 07:05
  • Could not find a simple example demonstrating usage of exoplayer. – jay May 11 '16 at 04:10
  • @AMRUTHAKALIVARAPU use ExoMedia a wrapper around exoplayer It's worked really good . – Amir May 11 '16 at 04:11