【问题标题】:Android 2.2 VideoView "Sorry, Video cannot be played" with H264 .MP4Android 2.2 VideoView“抱歉,视频无法播放”与 H264 .MP4
【发布时间】:2011-09-05 08:22:07
【问题描述】:

我有一个 Activity 可以逐步播放流式视频,代码如下:

布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <VideoView android:id="@+id/myVideo"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:layout_gravity="center"/>
</LinearLayout>

活动

public class PlayVideo extends Activity {

    public ProgressDialog progressDialog;

    /** Called when the activity is first created. */
    @Override
    public void onCreate( Bundle savedInstanceState ) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.video );
        progressDialog = ProgressDialog.show( this, "", "Loading...", true );
        Intent i = getIntent();
        startVideo( i.getStringExtra( "videoUrl" ) );
    }

    public void startVideo( String videoUrl ) {
        final VideoView videoView = ( VideoView ) findViewById( R.id.myVideo );

        videoView.setMediaController( new MediaController( this ) );
        videoView.setVideoURI( Uri.parse( videoUrl ) );

        videoView.setOnPreparedListener( new OnPreparedListener() {
            public void onPrepared( MediaPlayer arg0 ) {
                progressDialog.dismiss();
                videoView.requestFocus();
                videoView.start();
            }
        } );
    }    
}

这在大多数设备上都可以正常工作,但是我的客户有两台设备,一台是运行 2.2 的三星 Galaxy ace。另一个是ideos U8150(运行2.2),这两个设备上都不会播放视频。 ideos 有一个错误弹出并说“对不起,这个视频无法播放”,而音频在后台播放,三星也有同样的错误,但是当插入 ddms 时,唯一可能指示错误的输出是:

09-05 15:11:03.461: ERROR/QCvdec(95): Omx Flush issued when vdec is not initialized yet.
09-05 15:11:03.461: ERROR/QCvdec(95): Unsupported profile, level, or widht, height
09-05 15:11:03.461: ERROR/QCvdec(95): Unsupported clip
09-05 15:11:03.461: ERROR/QCvdec(95): Omx Flush issued when vdec is not initialized yet.
09-05 15:11:03.461: ERROR/QCvdec(95): Empty this buffer in Invalid State
09-05 15:11:03.461: ERROR/QCvdec(95): Omx Flush issued when vdec is not initialized yet.

我已经使用此处描述的设置在 H264+AAC 中对视频进行了编码:http://developer.android.com/guide/appendix/media-formats.html 并确保 moov 原子在 qt-fastart 等的正确位置。请参阅:http://www.sciencelearn.org.nz/content/download/7366/430467/version/14/file/08-future-of-radio-telescopes-sllg-ws.mp4

视频可在 2.3.3、摩托罗拉 Xoom、Galaxy S、Galaxy Tab 和 HTC Desire 上正常播放。有什么想法吗?

【问题讨论】:

  • 我可以获取您的 URL 来测试我的代码吗?我还从我的客户端接收 IP 摄像机的 rtsp 实时流,它是 H.264 AVC 媒体格式。我从资源中了解到它仅支持 SDK 3.0 及更高版本。我想看看您的链接如何支持 Galaxy S

标签: android h.264 android-videoview


【解决方案1】:

请参考android的默认视频编解码器支持http://developer.android.com/guide/appendix/media-formats.html, H.263 MPEG-4 (.mp4),是2.2设备的不错选择,,,

或者对于替代品,请参阅问题: FFmpeg on Android

【讨论】:

    猜你喜欢
    • 2011-09-18
    • 2012-11-07
    • 2013-12-04
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多