无法在我的Andr​​oid应用程序播放MP4视频 [英] Can't play mp4 video in my Android app

查看:365
本文介绍了无法在我的Andr​​oid应用程序播放MP4视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很想在我的Andr​​oid应用程序中播放mp4视频。我甚至写了一点code吧:

I very want to play mp4 video in my android app. I even wrote a bit of code for it:

String sourceUrl = "http://tvstream.cn.ru/storage/1kanal/20120530/"
       + "1kanal-20120530-01-14-00-20120530-03-16-00.mp4";

final VideoView videoView = (VideoView) findViewById(R.id.videoView);
getWindow().setFormat(PixelFormat.TRANSLUCENT);

final MediaController mediaController = new MediaController(this);
mediaController.setMediaPlayer(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse(sourceUrl));

videoView.setOnPreparedListener(new OnPreparedListener() {

    public void onPrepared(MediaPlayer mp) {
        videoView.requestFocus();
        videoView.start();
        mediaController.show();
    }
});

但是,没有什么工作:(当我启动我的应用程序在仿真器(安卓2.3.3)我有奇怪的堆栈跟踪的一些常见的错误codeS:

But nothing works :( When I launch my app in emulator (Android 2.3.3) I've got weird stacktrace with some common error codes:

几个小时关闭谷歌搜索和实验后,我决定尝试推出我的应用程序在真实的设备,看logcat的:

After few hours off googling and experiments I decided to try to launch my app on real device and watch logcat:

D/test.tv.activity.PlayerActivity( 3428): Player source: http://tvstream.cn.ru/storage/1kanal/20120530/1kanal-20120530-01-14-00-20120530-03-16-00.mp4
D/VideoView( 3428): onMeasure()
I/VideoView( 3428):     Setting size: 320x430
I/Launcher(  260): onWindowFocusChanged(false)
D/Launcher(  260): setWallpaperDimension() called
D/Launcher(  260): USE_NON_SCROLLABLE_IMAGE_WALLPAPER is true
I/ActivityManager(  163): Start proc org.reactivephone for broadcast org.reactivephone/ru.yandex.common.clid.ClidBroadcastReceiver: pid=3448 uid=10073 gids={1015, 3003}
I/ActivityManager(  163): No longer want com.sec.android.provider.badge (pid 2310): hidden #16
I/MediaPlayer( 3428): uri is:http://tvstream.cn.ru/storage/1kanal/20120530/1kanal-20120530-01-14-00-20120530-03-16-00.mp4
I/MediaPlayer( 3428): path is null
D/MediaPlayer( 3428): Couldn't open file on client side, trying server side
D/Launcher(  260): It's image wallpaper. suggestDesiredDimensions(-1,-1)
I/ActivityManager(  163): Displayed test.tv/.activity.PlayerActivity: +943ms
D/VideoView( 3428): onMeasure()
I/VideoView( 3428):     Setting size: 320x430
W/dalvikvm( 3406): threadid=5: spin on suspend #1 threadid=22 (pcf=0)
W/dalvikvm( 3406): threadid=5: spin on suspend resolved in 1154 msec
W/SearchableInfo(  163): Invalid searchable metadata for org.reactivephone/.ui.RegionForm: Search label must be a resource reference.
I/ActivityManager(  163): Start proc com.google.android.googlequicksearchbox for broadcast com.google.android.googlequicksearchbox/.SourceUpdateReceiver: pid=3457 uid=10027 gids={3003}
I/WindowOrientationListener(  163): orientation 295.6932 gives new rotation = 2
I/OrientationDebug(  163): [pwm] in MyOrientationListener.onOrientationChanged() rotation=3  mFancyRotationAnimation=0   now call mWindowManager.setRotation()
I/OrientationDebug(  163): [wms] in setRotation() rotation=3 alwaysSendConfiguration=false animFlags=0
I/OrientationDebug(  163): [wms] in setRotation() now call setRotationUnchecked()
I/WindowManager(  163): Setting rotation to 3, animFlags=0
I/ActivityManager(  163): Config changed: { scale=1.0 imsi=250/1 loc=ru_RU touch=3 keys=1/1/2 nav=1/1 orien=2 layout=18 uiMode=17 seq=7}
D/PhoneApp(  241): updateProximitySensorMode: lock already released.
I/ActivityThread( 3457): Pub com.google.android.googlequicksearchbox.shortcuts: com.google.android.googlequicksearchbox.WebHistoryProvider
I/ActivityThread( 3457): Pub com.google.android.googlequicksearchbox.google: com.google.android.googlequicksearchbox.google.GoogleSuggestionProvider
I/ActivityManager(  163): No longer want com.sec.android.widgetapp.clockweather.clockwidget (pid 1214): hidden #16
D/Finsky  ( 3406): [1] 2.run: Loaded library for account: [Y091GklnFtI4Ab1gmLOw-nJkJXQ]
D/Finsky  ( 3406): [1] 2.run: Finished loading 1 libraries.
W/dalvikvm( 3406): VFY: unable to resolve instance field 78
D/DfeApi  ( 3406): [1] DfeApiContext.getSmallestScreenWidthDp: smallestScreenWidthDp does not exist, using pre-ics hack.
E/QCvdec  (   95): Setparameter: unknown param 2130706451
W/TimedEventQueue(   95): Event 3 was not found in the queue, already cancelled?
E/QCvdec  (   95): Omx Flush issued when vdec is not initialized yet.
W/QCvdec  (   95): ======================================================================
W/QCvdec  (   95):                    Open Max Statistics                                
W/QCvdec  (   95): ======================================================================
W/QCvdec  (   95): empty this buffer rate = NaN
W/QCvdec  (   95): empty this buffer total time = 0
W/QCvdec  (   95): empty this buffer count = 0
W/QCvdec  (   95): ======================================================================
D/test.tv.activity.PlayerActivity( 3428): Player source: http://tvstream.cn.ru/storage/1kanal/20120530/1kanal-20120530-01-14-00-20120530-03-16-00.mp4
D/VideoView( 3428): onMeasure()
I/VideoView( 3428):     Setting size: 480x270
I/MediaPlayer( 3428): uri is:http://tvstream.cn.ru/storage/1kanal/20120530/1kanal-20120530-01-14-00-20120530-03-16-00.mp4
I/MediaPlayer( 3428): path is null
D/MediaPlayer( 3428): Couldn't open file on client side, trying server side
D/VideoView( 3428): onMeasure()
I/VideoView( 3428):     Setting size: 480x270
D/WifiService(  163): [mPersistState] : On
D/BatteryService(  163): update start
D/BatteryService(  163): update start
D/BatteryService(  163): update start
E/QCvdec  (   95): Setparameter: unknown param 2130706451
I/VideoView( 3428): start()
D/WifiService(  163): [mPersistState] : On
D/WifiService(  163): [mPersistState] : On
D/WifiWatchdogService(  163): (android.server.ServerThread) wntk (1c:af:f7:2e:7f:c8) does not require the watchdog
E/QCvdec  (   95): Unsupported profile, level, or widht, height
E/QCvdec  (   95): Unsupported clip
E/QCvdec  (   95): Unsupported profile, level, or widht, height
E/QCvdec  (   95): Unsupported clip
E/QCvdec  (   95): Omx Flush issued when vdec is not initialized yet.
E/QCvdec  (   95): Omx Flush issued when vdec is not initialized yet.
E/QCvdec  (   95): Empty this buffer in Invalid State
E/OMXCodec(   95): [OMX.qcom.video.decoder.avc] ERROR(0x8000100a, 0)
E/OMXCodec(   95): [OMX.qcom.video.decoder.avc] ERROR(0x8000100a, 0)
E/OMXCodec(   95): read : mState[9] is wrong...
E/MediaPlayer( 3428): error (1, -2147483648)
E/OMXCodec(   95): [OMX.qcom.video.decoder.avc] ERROR(0x8000100a, 0)
E/QCvdec  (   95): Omx Flush issued when vdec is not initialized yet.
D/VideoView( 3428): onMeasure()
I/VideoView( 3428):     Setting size: 335x270
I/VideoView( 3428): start()
E/MediaPlayer( 3428): start called in state 0
E/MediaPlayer( 3428): error (-38, 0)
E/MediaPlayer( 3428): Error (1,-2147483648)
D/VideoView( 3428): Error: 1,-2147483648
E/MediaPlayer( 3428): Error (-38,0)
D/VideoView( 3428): Error: -38,0
D/PowerManagerService(  163): reactivateScreenLocksLocked mProxIgnoredBecauseScreenTurnedOff=false
I/PowerManagerService(  163): Ulight 1->3|0
W/InputManagerService(  163): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40873ab8
I/PowerManagerService(  163): Light Animator Finished curIntValue=141
D/Finsky  ( 3406): [1] 5.onFinished: Installation state replication succeeded.
D/BatteryService(  163): update start
D/BatteryService(  163): update start
D/BatteryService(  163): update start

我试图找到一些有关OMX.qcom.video.de coder.avc]错误(0x8000100a,0),但没有发现什么有趣的。关于在客户端无法打开文件,试图服务器端计算器的问题有很多答案,但没有人帮助。

I try to find something about "OMX.qcom.video.decoder.avc] ERROR(0x8000100a, 0)", but didn't find nothing interesting. About "Couldn't open file on client side, trying server side" problem stackoverflow has many answers, but no one helped.

当我发动对ICS这个应用程序(在模拟器),我有类似的错误:

When I launch this app on ICS (in emulator) I've got similar errors:

06-01 10:22:14.674: I/NuCachedSource2(37): ERROR_END_OF_STREAM
06-01 10:22:15.375: I/OMXCodec(37): [OMX.google.h264.decoder] AVC profile = 100 (High), level = 30
06-01 10:22:15.384: I/OMXCodec(37): [OMX.google.h264.decoder] video dimensions are 320 x 240
06-01 10:22:15.384: I/OMXCodec(37): [OMX.google.h264.decoder] Crop rect is 320 x 240 @ (0, 0)
06-01 10:22:16.253: W/NetworkManagementSocketTagger(89): setKernelCountSet(10013, 0) failed with errno -2
06-01 10:22:16.374: I/Launcher(553): setLoadOnResume
06-01 10:22:16.584: D/MediaPlayer(602): getMetadata
06-01 10:22:16.614: I/NuCachedSource2(37): new range: offset= 0
06-01 10:22:16.694: I/ChromiumHTTPDataSource(37): connect to http://tvstream.cn.ru/storage/1kanal/20120530/1kanal-20120530-01-14-00-20120530-03-16-00.mp4 @0
06-01 10:22:16.834: E/SoftAVC(37): Decoder failed: -2
06-01 10:22:16.844: E/OMXCodec(37): [OMX.google.h264.decoder] ERROR(0x80001001, -1007)
06-01 10:22:16.884: D/AudioSink(37): bufferCount (4) is too small and increased to 12

据我所知,Android支持具有H264播放的视频去codeD(http://developer.android.com/guide/appendix/media-formats.html)。所以,任何人都可以告诉我,我做错了。

As I know, Android supports playback of video decoded with h264 (http://developer.android.com/guide/appendix/media-formats.html). So, can anyone tell me what I do wrong.

推荐答案

可能是你的文件使用了不支持配置文件,请注意官方的媒体格式页面只列出的 Baseline Profile的的作为支持H.264 AVC。

Probably your file is using an unsupported profile, notice that official media formats page only lists Baseline Profile as supported for H.264 AVC.

尝试转码的视频指定的Baseline Profile在<一个建议href="http://superuser.com/questions/371460/command-encoding-h264-baseline-profile-level-1-with-ffmpeg-and-libx264">this计算器问题,也就是说,如果你的容器是MP4运行:

Try transcoding the video specifying Baseline Profile as suggested in this stackoverflow question, i.e. if your container is MP4 run:

ffmpeg -i yourfile.mp4 -c:v libx264 -profile:v baseline -level 1 yourfile_BaselineProfile.mp4

如果这个工作是不是在你的code一个问题,你只需要使用支持的格式。

If this works it's not a issue in your code, you just have to use supported formats.

这篇关于无法在我的Andr​​oid应用程序播放MP4视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆