【问题标题】:Playing MP4 from my android app is very choppy从我的 Android 应用程序播放 MP4 非常不稳定
【发布时间】:2012-11-23 14:01:22
【问题描述】:

我的 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()));

向大家致以最诚挚的问候

【问题讨论】:

  • 视频的质量很重要,我的意思是视频可能是高清的,所以处理器不能很好地处理它。

标签: android video mp4


【解决方案1】:

据我了解这里的问题与视频本身无关。这只是您可以从两个来源获得的吞吐量。 android.resource:// 的东西似乎有性能问题,简单的文件访问没有。

您可以尝试简单地从两个来源读取文件,测量读取速度,看看罪魁祸首是否真的是 I/O 吞吐量。

【讨论】:

    猜你喜欢
    • 2015-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-09
    相关资源
    最近更新 更多