我有一个奇怪的问题,我的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卡里一切正常,如果我使用raw资源文件夹内的文件,我在视频上有问题。以下似乎是解决方案,但对我来说不是一个好的解决方案。
//NOT OK
mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/"+R.raw.decart));
// OK
mVideoView.setVideoURI(Uri.parse(new File("/sdcard/decart.mp4").toString()));向大家致以最美好的问候
发布于 2012-12-03 02:41:11
据我所知,这个问题与视频本身没有任何关系。它只是您可以从两个来源获得的吞吐量。android.resource://内容似乎存在性能问题,而简单的文件访问则没有。
您可以尝试简单地从两个源读取文件,测量读取速度,并查看罪魁祸首是否真的是I/O吞吐量。
https://stackoverflow.com/questions/13530631
复制相似问题