0

I'm trying to create an app in which user can play In-App videos (videos already packaged in the application). No SDCard or Online streaming is going on.

But no matter what strategy I use I'm not able to run a simple .mp4 video in my app. I've tried placing video in assests folder but no luck. I've tried placing video in res/raw folder, again no luck.

Every time I run the app it says - Cannot play this video.

Earlier I when used just VideoView to run the video, now I'm using MediaController along with VideoView the error message keeps coming

Please help as it's troubling for quite some time and no matter what solution I use, I'm still unable to run a simple video.

My Activity code:

    public class MainActivity extends Activity {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            MediaController mediac;
            VideoView video1;
            mediac = new MediaController(this);        
            video1 = (VideoView) findViewById(R.id.vv01);
            video1.setMediaController(mediac);
            mediac.setAnchorView(video1);

            video1.setVideoURI(Uri.parse("android.resource://com.example.test/raw/aa"));
video1.start();

        } 

My xml file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


    <VideoView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/vv01"
        android:contentDescription="@string/app_name"
        />

</LinearLayout>

The log cat when I try to run the application:

08-26 13:27:31.023: I/dalvikvm(624): threadid=3: reacting to signal 3
08-26 13:27:31.593: I/dalvikvm(624): Wrote stack traces to '/data/anr/traces.txt'
08-26 13:27:31.643: I/dalvikvm(624): threadid=3: reacting to signal 3
08-26 13:27:31.913: I/dalvikvm(624): Wrote stack traces to '/data/anr/traces.txt'
08-26 13:27:31.923: D/dalvikvm(624): GC_CONCURRENT freed 147K, 3% free 9345K/9607K, paused 7ms+7ms
08-26 13:27:32.053: I/dalvikvm(624): threadid=3: reacting to signal 3
08-26 13:27:32.083: I/dalvikvm(624): Wrote stack traces to '/data/anr/traces.txt'
08-26 13:27:32.533: I/dalvikvm(624): threadid=3: reacting to signal 3
08-26 13:27:32.564: I/dalvikvm(624): Wrote stack traces to '/data/anr/traces.txt'
08-26 13:27:33.033: I/dalvikvm(624): threadid=3: reacting to signal 3
08-26 13:27:33.063: I/dalvikvm(624): Wrote stack traces to '/data/anr/traces.txt'
08-26 13:27:33.613: D/MediaPlayer(624): getMetadata
08-26 13:27:33.973: E/MediaPlayer(624): error (1, -2147483648)
08-26 13:27:34.093: E/MediaPlayer(624): Error (1,-2147483648)
08-26 13:27:34.093: D/VideoView(624): Error: 1,-2147483648
Harry
  • 3
  • 2
  • 9
  • Make sure you added internet permission when you try to stream it with your videoviewer. Can you look at the logcat error log and paste it here? There should be an error output when you get the message "this video cannot be played". – Infinity Aug 26 '12 at 07:43

1 Answers1

0

You have to declare VideoView outside the onStart(and the Media Controller too).

If that does not work use try/catch to each command and Log.e

MayTheSchwartzBeWithYou
  • 1,181
  • 1
  • 16
  • 32
  • Hi Peter, I did as suggested by you but no luck. Quynh and Peter, I'm attaching the log cat for your reference. – Harry Aug 26 '12 at 08:00
  • http://developer.android.com/reference/android/widget/VideoView.html I think you must have some functions like OnCompletionListener etc. Also have you tried making it Async? – MayTheSchwartzBeWithYou Aug 26 '12 at 11:14
  • No there is no OnCompletionListener function or anything in the code. Also I didn't try to make it Async. Does it really necessary ? Everywhere when I tried to search the code for running video file using Video View, I only got above or similar to above code. No Sync/Async whatsoever. Peter - can you please run the above code and see what's wrong going on ? – Harry Aug 26 '12 at 12:38