我正在制作一个项目,使用这个简单的代码和videoview,可以播放3gp和mp4格式的视频文件。
vv = (VideoView) findViewById(R.id.videoView);
vv.setVideoPath(filename);
vv.setMediaController(new MediaController(this));
vv.requestFocus();
vv.start();
我希望您能够播放mkv、flv和avi格式的文件。我搜索了一下,发现使用Votamio是个不错的选择。我试过了,下载了Vitamio的示例项目,并将其库文件(即InitActivity)导入到该示例项目中。我尝试在其中播放简单的mp4文件,但仍无法播放。
请问有什么建议可以让我能够播放所有视频格式吗?
更新1:使用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();
}
}
我作为用户使用
if (!LibsChecker.checkVitamioLibs(this))
return;
我得到的Logcat日志如下:
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
AndroidManifest.xml
中添加 ViewVideo 活动,其他的都应该没问题。 - Ahmed Nawaz