3
votes

I am making a project in which i am able to play video files that are of 3gp amd mp4 formats using this simple code that uses videoview

vv = (VideoView) findViewById(R.id.videoView);
vv.setVideoPath(filename);
vv.setMediaController(new MediaController(this));
vv.requestFocus();
vv.start();

I want this to play mkv, flv, avi formats files also. I did searching for this, and i get a option regarding votamio. I tried that too. I downloaded the demoproject of vitamio and imported its library i.e InitActivity in this demoproject and i tried to play simple mp4 file in that, But that also is not playing. So can anyone suggest what must i do so that i am able to play all video formats?

Update 1 using Vitamio:

import io.vov.vitamio.LibsChecker;
import io.vov.vitamio.MediaPlayer;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;


public class ViewVideo extends Activity {
      private String filename;
      VideoView vv;
      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            System.gc();
            if (!LibsChecker.checkVitamioLibs(this))
                return;
            Intent i = getIntent();
            Bundle extras = i.getExtras();
            filename = extras.getString("videofilename");
            // vv = new VideoView(getApplicationContext());
            setContentView(R.layout.activity_view);
            vv = (VideoView) findViewById(R.id.videoView);
            vv.setVideoPath(filename);
            vv.setMediaController(new MediaController(this));
            vv.requestFocus();
            vv.start();
      }
}

As i use

if (!LibsChecker.checkVitamioLibs(this))
                    return;

The Logcat i got...

06-12 13:35:53.952: E/AndroidRuntime(8078): FATAL EXCEPTION: main
06-12 13:35:53.952: E/AndroidRuntime(8078): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.videoplayer/com.example.videoplayer.ViewVideo}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.videoplayer/io.vov.vitamio.activity.InitActivity}; have you declared this activity in your AndroidManifest.xml?
06-12 13:35:53.952: E/AndroidRuntime(8078):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at android.app.ActivityThread.access$1500(ActivityThread.java:121)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at android.os.Looper.loop(Looper.java:130)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at android.app.ActivityThread.main(ActivityThread.java:3701)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at java.lang.reflect.Method.invokeNative(Native Method)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at java.lang.reflect.Method.invoke(Method.java:507)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at dalvik.system.NativeStart.main(Native Method)
06-12 13:35:53.952: E/AndroidRuntime(8078): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.videoplayer/io.vov.vitamio.activity.InitActivity}; have you declared this activity in your AndroidManifest.xml?
06-12 13:35:53.952: E/AndroidRuntime(8078):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at android.app.Activity.startActivityForResult(Activity.java:2827)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at android.app.Activity.startActivity(Activity.java:2933)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at io.vov.vitamio.LibsChecker.checkVitamioLibs(LibsChecker.java:47)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at com.example.videoplayer.ViewVideo.onCreate(ViewVideo.java:19)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-12 13:35:53.952: E/AndroidRuntime(8078):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
06-12 13:35:53.952: E/AndroidRuntime(8078):     ... 11 more
1
have you declared this activity in your AndroidManifest.xml? I am seeing this error. in your log.Ahmed Nawaz
Add ViewVideo activity in your AndroidManifest.xml everything else should be fine.Ahmed Nawaz
@AhmedNawaz if I am not using this if (!LibsChecker.checkVitamioLibs(this)) return; its running finenawaab saab
Some times fine and some times have problem. This makes sure that library is present in your app.Ahmed Nawaz
@AhmedNawaz I think the library is not working fine.. as I said if I dont use Vitamio Library and not even use if (!LibsChecker.checkVitamioLibs(this)) return; the project is working fine and playing mp4 files perfectly, but if i use lib and this code than it gives me errornawaab saab

1 Answers

4
votes

You can Use Vitamio Library for Playing these formats. Here it is. https://github.com/yixia/VitamioBundle

Video Playing code is same. Just import these and use Vitamio VideoView.

import io.vov.vitamio.MediaPlayer;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;

Check Library in onCreateView like following.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
        return;
    setContentView(R.layout.layout);

Playvideo Like following

mVideoView.setVideoPath(path);
mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
mController = new MediaController(this);
mVideoView.setMediaController(mController);

and following should be your videoview.

<io.vov.vitamio.widget.VideoView
 android:id="@+id/surface_view"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_centerHorizontal="true"
  android:layout_centerVertical="true" />

Update: Following errors found in your project after review.

1) use io.vov.vitamio.widget.VideoView instead of VideoView as I mentioned above.

<io.vov.vitamio.widget.VideoView 
        android:id="@+id/videoView"
           android:layout_width="fill_parent"
             android:layout_alignParentLeft="true"
             android:layout_alignParentTop="true"
             android:layout_alignParentBottom="true"
             android:layout_height="fill_parent"/>

2) define InitActivity in Your AndroidManifest.xml following is the code.

<activity
 android:name="io.vov.vitamio.activity.InitActivity"
                android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
 android:launchMode="singleTop"
 android:theme="@android:style/Theme.NoTitleBar"
 android:windowSoftInputMode="stateAlwaysHidden"/>

3) Missing Permissions Add them in your AndroidManifest.xml e.g. Read/Write etc