2

I have already seen the other questions similar to mine, but the problem persists. Thanks in advance.

Here's the code

package com.akk.mysecondvideo;

import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.widget.VideoView;

public class MySecondVideo extends Activity {

Context context;
MediaPlayer mp;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    VideoView videoView = (VideoView)findViewById(R.id.VideoView);
    //MediaController mediaController = new MediaController(this);
    // mediaController.setAnchorView(videoView);
    //videoView.setMediaController(mediaController);

    Uri uri = Uri.parse("android.resource://com.akk.mysecondvideo/"
            + R.raw.bommarillu);

    videoView.setVideoURI(uri);

    //mp = new MediaPlayer();
    //mp = MediaPlayer.create(context, R.raw.bommarillu);


    videoView.start(); 
}
}

It shows a force close when i try to run it, and the logcat shows error NULLPOINTEREXCEPTION in line 28 which is videoView.setVideoURI(uri);

VideoView is part of main.xml. The main.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"
>
<VideoView 
     android:layout_height="fill_parent"
     android:layout_width="fill_parent" 
     android:id="@+id/VideoView" />
</LinearLayout>
Ashwyn
  • 659
  • 1
  • 6
  • 18

3 Answers3

1

Did you check to see if uri is null?

Try adding this line before videoView.setVidoeURI(uri) :

if (null == uri)
   Toast.makeText(this, "URI IS NULL", Toast.LENGTH_LONG).show();

If the toast notification shows up then the URI didn't parse correctly

slayton
  • 20,123
  • 10
  • 60
  • 89
  • Thanks for the reply, but now its showing **can't play this video** – Ashwyn Apr 18 '12 at 14:03
  • 2
    does video is in supported format? http://developer.android.com/guide/appendix/media-formats.html#formats-table go to video section of this table – Selvin Apr 18 '12 at 14:15
  • seems this is the case, as my video is in .mp4 format, which doesn't seem to be supported, thanks! – Ashwyn Apr 18 '12 at 14:43
  • @Selvin sorry about previous comment, but it says that it supports .mp4 as well as .3gp format, while i am not able to run either – Ashwyn Apr 18 '12 at 14:53
  • It says, can't play video, video not supported! – Ashwyn Apr 18 '12 at 14:54
  • @Ashwyn see these: http://stackoverflow.com/questions/3263736/playing-a-video-in-videoview-in-android http://stackoverflow.com/questions/7806261/strange-behavior-of-android-videoview-cant-play-video http://stackoverflow.com/questions/2544365/android-cant-play-any-videos-mp4-mov-3gp-etc – slayton Apr 18 '12 at 16:15
0

I dont see any problem as such. But couple of suggestions I would like to tell you

  • Name the widget in XML different than the widget name e.g myVideoView instead of VideoView
  • videoView.setMediaController(new MediaController(this));
  • videoView.requestFocus();

Check if this works. I have the same code as you I will create a project and will give you my inputs.

Till that time try this

ValayPatel
  • 1,094
  • 12
  • 15
0

Try this sample code:

Uri uri = Uri.parse("android.resource://com.akk.mysecondvideo/raw/bommarillu");
Charles Menguy
  • 40,830
  • 17
  • 95
  • 117