我正在制作一个项目,我可以使用这个使用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的demoproject并导入了它的库,即在这个demoproject中的InitActivity,我试图在其中播放简单的mp4文件,但这也没有播放。 所以有人可以建议我必须做什么才能播放所有视频格式吗?
使用Vitamio更新1:
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
答案 0 :(得分:3)
您可以使用Vitamio
库来播放这些格式。这里是。 https://github.com/yixia/VitamioBundle
视频播放代码相同。只需导入这些并使用Vitamio VideoView。
import io.vov.vitamio.MediaPlayer;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
在onCreateView中检查库,如下所示。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.layout);
Playvideo喜欢以下
mVideoView.setVideoPath(path);
mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
mController = new MediaController(this);
mVideoView.setMediaController(mController);
以下应该是您的视频观看。
<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" />
更新: 审核后发现项目中发现错误。
1)如上所述,使用io.vov.vitamio.widget.VideoView
代替VideoView
。
<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)在InitActivity
中定义AndroidManifest.xml
以下是代码。
<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)遗失Permissions
将其添加到AndroidManifest.xml
中,例如读/写等