我的 Hackberry 板与 Android 4.0.4 有一个奇怪的问题,我必须全屏播放视频,但视频非常不稳定,如果从我的应用程序播放,速度非常慢。如果我在默认媒体播放器上播放相同的 mp4 视频,一切都很好而且很快。我的三星 S3 上的相同 apk 在应用程序和媒体播放器中也很快。
这是我的布局
<RelativeLayout 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:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"/>
</RelativeLayout>
这是我用来播放视频的代码
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mVideoView = (VideoView) findViewById(R.id.surface_view);
mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/"+R.raw.decart));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.start();
和清单
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:persistent="true"
android:largeHeap="true" >
<activity
android:name=".MainActivity"
android:screenOrientation="landscape"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
任何想法?
我也做了一个测试,如果我把我的视频放在 SD-CARD 中一切正常,如果我使用原始资源文件夹中的文件,我的视频就有问题。以下似乎是解决方案,但对我来说不是一个好的解决方案。
//NOT OK
mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/"+R.raw.decart));
// OK
mVideoView.setVideoURI(Uri.parse(new File("/sdcard/decart.mp4").toString()));
向大家致以最诚挚的问候