Android MediaPlayer 错误 (1, -2147483648)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11540076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:58:54  来源:igfitidea点击:

Android MediaPlayer error (1, -2147483648)

androidmedia-playerandroid-videoview

提问by Ayberk ?zgür

I have two different videos which I'm trying to load into a VideoViewusing

我有两个不同的视频,我正在尝试将它们加载到VideoView使用中

videoView.setVideoURI(Uri.parse(url));

The two videos, let them be video 1and video 2, have the following specs (extracted using ffmpeg -i); in fact, they are two different encodings of the same video:

这两个视频,让它们分别为video 1video 2,具有以下规格(使用 提取ffmpeg -i);实际上,它们是同一视频的两种不同编码:

  1. Video 1:

    Seems stream 0 codec frame rate differs from container frame rate: 180000.00 (180000/1) -> 90000.00 (180000/2)
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '4fbfd5ece4b0932236fc234d.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: mp42isomavc1
        creation_time   : 2011-12-03 04:43:46
        genre           : Trailer
        artist          : Paramount Pictures
        title           : Captain America: The First Avenger - Theatrical Trailer #2
        encoder         : HandBrake 4344svn 2011111001
        date            : 2011
      Duration: 00:02:30.67, start: 0.000000, bitrate: 6738 kb/s
        Stream #0.0(und): Video: h264 (High), yuv420p, 1920x800 [PAR 1:1 DAR 12:5], 6575 kb/s, 23.97 fps, 90k tbr, 90k tbn, 180k tbc
        Metadata:
          creation_time   : 2011-12-03 04:43:46
        Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 159 kb/s
        Metadata:
          creation_time   : 2011-12-03 04:43:46
    
  2. Video 2:

    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '500416ea44aeb4b95d5ae8a0_hd.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        creation_time   : 2011-12-03 04:43:46
        title           : Captain America: The First Avenger - Theatrical Trailer #2
        artist          : Paramount Pictures
        date            : 2011
        encoder         : Lavf53.32.100
        genre           : Trailer
      Duration: 00:02:30.69, start: 0.000000, bitrate: 2045 kb/s
        Stream #0.0(und): Video: h264 (High), yuv420p, 1280x720 [PAR 27:20 DAR 12:5], 1889 kb/s, 23.99 fps, 90k tbr, 180k tbn, 180k tbc
        Metadata:
          creation_time   : 2011-12-03 04:43:46
        Stream #0.1(eng): Audio: aac, 44100 Hz, stereo, s16, 151 kb/s
        Metadata:
          creation_time   : 2011-12-03 04:43:46
    
  1. 视频1:

    Seems stream 0 codec frame rate differs from container frame rate: 180000.00 (180000/1) -> 90000.00 (180000/2)
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '4fbfd5ece4b0932236fc234d.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: mp42isomavc1
        creation_time   : 2011-12-03 04:43:46
        genre           : Trailer
        artist          : Paramount Pictures
        title           : Captain America: The First Avenger - Theatrical Trailer #2
        encoder         : HandBrake 4344svn 2011111001
        date            : 2011
      Duration: 00:02:30.67, start: 0.000000, bitrate: 6738 kb/s
        Stream #0.0(und): Video: h264 (High), yuv420p, 1920x800 [PAR 1:1 DAR 12:5], 6575 kb/s, 23.97 fps, 90k tbr, 90k tbn, 180k tbc
        Metadata:
          creation_time   : 2011-12-03 04:43:46
        Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 159 kb/s
        Metadata:
          creation_time   : 2011-12-03 04:43:46
    
  2. 视频2:

    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '500416ea44aeb4b95d5ae8a0_hd.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        creation_time   : 2011-12-03 04:43:46
        title           : Captain America: The First Avenger - Theatrical Trailer #2
        artist          : Paramount Pictures
        date            : 2011
        encoder         : Lavf53.32.100
        genre           : Trailer
      Duration: 00:02:30.69, start: 0.000000, bitrate: 2045 kb/s
        Stream #0.0(und): Video: h264 (High), yuv420p, 1280x720 [PAR 27:20 DAR 12:5], 1889 kb/s, 23.99 fps, 90k tbr, 180k tbn, 180k tbc
        Metadata:
          creation_time   : 2011-12-03 04:43:46
        Stream #0.1(eng): Audio: aac, 44100 Hz, stereo, s16, 151 kb/s
        Metadata:
          creation_time   : 2011-12-03 04:43:46
    

I am aware that AAC support came with Honeycomb, and therefore I tested the videos with several devices; the results are given below:

我知道 Honeycomb 支持 AAC,因此我在多个设备上测试了视频;结果如下:

  1. SGS II with custom 4.0.3 OS(Sensation ROM 3.4 with CF-Root kernel) - Video 1:OK - Video2:OK
  2. SGS I with Samsung 2.3.3 OS - Video 1:error (1, -2147483648) - Video 2:OK
  3. SGS I with custom 4.0.3 OS(ICS SGS TEAM ROM with Devil kernel) - Video 1:error (1, -2147483648) - Video 2:OK
  4. Nexus One with original 2.3.6 OS - Video 1:See (1) below - Video 2:See (2) below
  5. Emulator with 2.2 OS - Video 1:error (1, -2147483648) - Video 2:error (1, -2147483648)
  6. Emulator with 4.0.3 OS - Video 1:error (1, -2147483648) - Video 2:error (1, -2147483648)
  1. SGS II with custom 4.0.3 OS(Sensation ROM 3.4 with CF-Root kernel) - Video 1:OK - Video2:OK
  2. SGS I with Samsung 2.3.3 OS - Video 1:error (1, -2147483648) - Video 2:OK
  3. SGS I with custom 4.0.3 OS(ICS SGS TEAM ROM with Devil kernel) - Video 1:error (1, -2147483648) - Video 2:OK
  4. Nexus One with original 2.3.6 OS - Video 1:See (1) below - Video 2:See (2) below
  5. Emulator with 2.2 OS - Video 1:error (1, -2147483648) - Video 2:error (1, -2147483648)
  6. Emulator with 4.0.3 OS - Video 1:error (1, -2147483648) - Video 2:error (1, -2147483648)

Both videos play fine in Google Chrome in a PC. It might be useful to add that in the OK case, video and audio both play correctly. In the error (1, -2147483648) case, the same log is spewed from all devices (except Nexus One):

这两个视频都可以在 PC 上的 Google Chrome 中正常播放。添加在 OK 情况下视频和音频都可以正确播放的内容可能会很有用。在错误 (1, -2147483648) 情况下,所有设备(Nexus One 除外)都输出相同的日志:

07-18 10:25:10.996: I/MediaPlayer(17860): uri is:http://s3-eu-west-1.amazonaws.com/cf-templates-k6ohn88yswx5-eu-west-1/videos/4fbc88e7e4b0b0896e877764/4fbfd5ece4b0932236fc234d.mp4
07-18 10:25:10.996: I/MediaPlayer(17860): path is null
07-18 10:25:10.996: D/MediaPlayer(17860): Couldn't open file on client side, trying server side
07-18 10:25:39.859: D/MediaPlayer(17860): getMetadata
07-18 10:25:45.070: E/MediaPlayer(17860): error (1, -2147483648)
07-18 10:25:45.074: E/MediaPlayer(17860): Error (1,-2147483648)
07-18 10:25:45.078: D/VideoView(17860): Error: 1,-2147483648

In the (1) case, the following log is spewed from Nexus One, and the video never loads:

在 (1) 情况下,以下日志是从 Nexus One 中喷出的,并且视频永远不会加载:

07-18 13:49:20.115: D/MediaPlayer(10109): Couldn't open file on client side, trying server side
07-18 13:49:20.115: I/StagefrightPlayer(68): setDataSource('http://s3-eu-west-1.amazonaws.com/cf-templates-k6ohn88yswx5-eu-west-1/videos/4fbc88e7e4b0b0896e877764/4fbfd5ece4b0932236fc234d.mp4')
07-18 13:49:20.135: I/NuHTTPDataSource(68): connect to s3-eu-west-1.amazonaws.com:80/cf-templates-k6ohn88yswx5-eu-west-1/videos/4fbc88e7e4b0b0896e877764/4fbfd5ece4b0932236fc234d.mp4 @0
07-18 13:49:20.155: I/ActivityManager(98): Displayed com.woisio/.video.VideoActivity: +450ms
07-18 13:49:20.795: I/NuCachedSource2(68): Keep alive
07-18 13:49:22.185: I/OMXCodec(68): [OMX.qcom.video.decoder.avc] allocating 4 buffers of size 460800 on input port
07-18 13:49:22.195: I/OMXCodec(68): [OMX.qcom.video.decoder.avc] allocating 8 buffers of size 2304000 on output port
07-18 13:49:25.325: D/dalvikvm(9499): GC_EXPLICIT freed 13K, 50% free 2726K/5379K, external 1625K/2137K, paused 116ms
07-18 13:49:27.525: I/NuCachedSource2(68): Keep alive
07-18 13:49:28.235: I/NuCachedSource2(68): Cache full, done prefetching for now
07-18 13:49:30.275: D/dalvikvm(9902): GC_EXPLICIT freed 8K, 50% free 2714K/5379K, external 1625K/2137K, paused 69ms
07-18 13:49:34.255: D/Finsky(9066): [1] 5.onFinished: Installation state replication succeeded.
07-18 13:49:35.855: I/NuCachedSource2(68): Keep alive
07-18 13:49:39.055: D/dalvikvm(9911): GC_EXPLICIT freed 22K, 50% free 2710K/5379K, external 1625K/2137K, paused 38ms
07-18 13:49:42.575: I/NuCachedSource2(68): Keep alive
07-18 13:49:43.285: I/NuCachedSource2(68): Keep alive
07-18 13:49:44.095: D/dalvikvm(9918): GC_EXPLICIT freed 7K, 50% free 2708K/5379K, external 1625K/2137K, paused 66ms
07-18 13:49:49.085: D/dalvikvm(9925): GC_EXPLICIT freed 15K, 49% free 3268K/6407K, external 1625K/2137K, paused 50ms
07-18 13:49:50.925: I/NuCachedSource2(68): Keep alive
07-18 13:49:54.115: D/dalvikvm(6756): GC_EXPLICIT freed 9K, 44% free 3774K/6727K, external 1625K/2137K, paused 77ms
07-18 13:49:57.685: I/NuCachedSource2(68): Keep alive
07-18 13:49:58.375: I/NuCachedSource2(68): Keep alive
07-18 13:49:59.105: D/dalvikvm(9066): GC_EXPLICIT freed 385K, 53% free 3186K/6727K, external 1625K/2137K, paused 66ms
07-18 13:50:05.955: I/NuCachedSource2(68): Keep alive
07-18 13:50:06.045: D/dalvikvm(8047): GC_EXPLICIT freed 9K, 47% free 3830K/7111K, external 1625K/2137K, paused 86ms
07-18 13:50:09.465: I/3gw.Service(488): Mobile Network not connected - not roaming
07-18 13:50:12.765: I/NuCachedSource2(68): Keep alive
07-18 13:50:13.465: I/NuCachedSource2(68): Keep alive
07-18 13:50:18.775: I/WindowManager(98): Setting rotation to 3, animFlags=0
07-18 13:50:18.795: I/ActivityManager(98): Config changed: { scale=1.0 imsi=286/2 loc=en_US touch=3 keys=1/1/2 nav=3/1 orien=2 layout=34 uiMode=17 seq=34}
07-18 13:50:18.895: D/dalvikvm(169): GC_EXTERNAL_ALLOC freed 108K, 48% free 3253K/6215K, external 5172K/5180K, paused 37ms
07-18 13:50:21.005: I/NuCachedSource2(68): Keep alive
07-18 13:50:21.265: D/dalvikvm(98): GC_EXPLICIT freed 394K, 42% free 6631K/11335K, external 4458K/5567K, paused 109ms

In the (2) case, the following log is spewed from Nexus One and as you can see, ends with an error (1, -2147483648):

在 (2) 的情况下,以下日志是从 Nexus One 发出的,如您所见,以错误结尾 (1, -2147483648):

07-18 13:47:03.595: D/MediaPlayer(10059): Couldn't open file on client side, trying server side
07-18 13:47:03.595: I/StagefrightPlayer(68): setDataSource('http://s3-eu-west-1.amazonaws.com/cf-templates-k6ohn88yswx5-eu-west-1/videos/4ff4514444aec3d2f9f07ead/500416ea44aeb4b95d5ae8a0_hd.mp4')
07-18 13:47:03.605: I/NuHTTPDataSource(68): connect to s3-eu-west-1.amazonaws.com:80/cf-templates-k6ohn88yswx5-eu-west-1/videos/4ff4514444aec3d2f9f07ead/500416ea44aeb4b95d5ae8a0_hd.mp4 @0
07-18 13:47:03.625: I/ActivityManager(98): Displayed com.woisio/.video.VideoActivity: +505ms
07-18 13:47:05.355: I/OMXCodec(68): [OMX.qcom.video.decoder.avc] allocating 4 buffers of size 460800 on input port
07-18 13:47:05.355: I/OMXCodec(68): [OMX.qcom.video.decoder.avc] allocating 8 buffers of size 1382400 on output port
07-18 13:47:05.365: I/NuCachedSource2(68): Keep alive
07-18 13:47:08.375: D/MediaPlayer(10059): getMetadata
07-18 13:47:08.745: D/dalvikvm(9925): GC_EXPLICIT freed 651K, 49% free 3275K/6407K, external 1625K/2137K, paused 68ms
07-18 13:47:09.205: I/3gw.Service(488): Mobile Network not connected - not roaming
07-18 13:47:11.565: I/NuCachedSource2(68): Cache full, done prefetching for now
07-18 13:47:12.095: I/NuCachedSource2(68): Keep alive
07-18 13:47:14.245: W/QCvdec(68): H264_Utils::check_header 
07-18 13:47:14.245: W/QCvdec(68): check_header: start code 33
07-18 13:47:14.245: W/QCvdec(68): H264_Utils::check_header 
07-18 13:47:14.245: W/QCvdec(68): check_header: start code 10
07-18 13:47:14.245: W/QCvdec(68): Parsing Error unsupported profile or level
07-18 13:47:14.245: W/QCvdec(68): ETB in Invalid State
07-18 13:47:14.245: E/OMXCodec(68): [OMX.qcom.video.decoder.avc] ERROR(0x8000100a, 0)
07-18 13:47:14.245: E/MediaPlayer(10059): error (1, -2147483648)
07-18 13:47:14.285: E/MediaPlayer(10059): Error (1,-2147483648)
07-18 13:47:14.285: D/VideoView(10059): Error: 1,-2147483648

From what I have read, the error (1, -2147483648) may correspond to unsupported codecs, corrupt metadata or incorrect file headers. If it is so, could you point me in the right direction as to use which codec? Thanks.

根据我的阅读,错误 (1, -2147483648) 可能对应于不受支持的编解码器、元数据损坏或文件头不正确。如果是这样,您能否指出我使用哪种编解码器的正确方向?谢谢。

回答by sturrockad

Just to clarify something for anyone reading this question based on the title.

只是为了根据标题为阅读此问题的任何人澄清一些事情。

When looking at the error value (1, -2147483648), the '1' value corresponds to the constant in MediaPlayer.MEDIA_ERROR_UNKNOWN.

查看错误值 (1, -2147483648) 时,“1”值对应于MediaPlayer.MEDIA_ERROR_UNKNOWN 中的常量。

-2147483648 corresponds to hexadecimal 0x80000000 which is defined as UNKNOWN_ERROR in frameworks/native/include/utils/Errors.h

-2147483648 对应于在 frameworks/native/include/utils/Errors.h 中定义为 UNKNOWN_ERROR 的十六进制 0x80000000

This shows that the error's source is hard to pin down as it is quite a generic return value, thrown by codec and compatibility issues as mentioned above but also thread cancellations and several other types.

这表明错误的来源很难确定,因为它是一个非常通用的返回值,由上面提到的编解码器和兼容性问题以及线程取消和其他几种类型引发。

For your issue, I would recommend consulting the Android Supported Media Formatswith compatible Android versions and see if the encoding type is the cause of your problem, but as mentioned above the Unknown Error response can be caused by a number of problems.

对于您的问题,我建议您咨询具有兼容 Android 版本的Android 支持的媒体格式,看看编码类型是否是您的问题的原因,但如上所述,未知错误响应可能是由许多问题引起的。

回答by Rod Lima

I was facing the same error on Android P (Pixel 2 XL), but all I had to do was put android:usesCleartextTraffic="true"on my AndroidManifest.xmlapplication tag.

我在 Android P(Pixel 2 XL)上遇到了同样的错误,但我所要做的就是放在android:usesCleartextTraffic="true"我的AndroidManifest.xml应用程序标签上。

回答by Nam Trung

For streaming, the Android site has a note:

对于流媒体,Android 网站有一个说明:

For 3GPP and MPEG-4 containers, the moov atom must precede any mdat atoms, but must succeed the ftyp atom.

对于 3GPP 和 MPEG-4 容器,moov 原子必须在任何 mdat 原子之前,但必须在 ftyp 原子之后。

I got the same error before moving the moovatom. In order to fix this, you can use mp4Boxwith this command:

在移动moov原子之前我遇到了同样的错误。为了解决这个问题,您可以通过以下命令使用mp4Box

MP4Box -hint output.mp4 

Most of my videos can stream after that. If it does not work, try this with ffmpeg:

之后我的大部分视频都可以流式传输。如果它不起作用,请尝试使用 ffmpeg:

ffmpeg -i input.flv -f mp4 -vcodec libx264 -vprofile baseline -acodec libfaac -ar 16k -ab 32k output.mp4
MP4Box -hint output.mp4 

There are other tools you can find here.

您可以在此处找到其他工具。

回答by Anshu

I am also getting same MEDIA_ERROR_UNKNOWNerror issue for playing video(rtsp).

我也在播放视频(rtsp)时遇到相同的MEDIA_ERROR_UNKNOWN错误问题。

In my case I am finding issue with my wifi. Some security reasons wifi is restricted for RTSP protocol. So that I'm facing this MEDIA_ERROR_UNKNOWN error issue. Once check with your network permissions.

就我而言,我发现我的 wifi 有问题。一些安全原因 wifi 受限于 RTSP 协议。所以我正面临这个 MEDIA_ERROR_UNKNOWN 错误问题。一旦检查您的网络权限。

When I am moving to mobile data for playing video it's working fine for me. May be this will be helpful whoever facing same kind of error :).

当我转向移动数据播放视频时,它对我来说很好用。可能这对面临同样错误的人会有所帮助:)。

回答by Renaud Boulard

Take care of the support media type and resolution of your device. Error error (1, -2147483648)often, appear when your video media type, codecs, or resolution is not supported by your device.

注意您设备的支持媒体类型和分辨率。error (1, -2147483648)经常出现错误,当您的设备不支持您的视频媒体类型、编解码器或分辨率时出现。

Checkout the media type supported by Android in the documentation :

在文档中查看 Android 支持的媒体类型:

https://developer.android.com/guide/appendix/media-formats.html

https://developer.android.com/guide/appendix/media-formats.html

For example, we can notice that device above 3.0 support .mp4, but not all of them support HD 720p.

例如,我们可以注意到 3.0 以上的设备支持 .mp4,但并非所有设备都支持 HD 720p。

回答by jdramer

I had a similar issue. In my case the video would play fine when I downloaded it to the phone first and then played it. But when I tried to use Progressive HTTP I would get the same error noted in the OP.

我有一个类似的问题。在我的情况下,当我先将视频下载到手机然后播放时,视频会播放得很好。但是当我尝试使用渐进式 HTTP 时,我会得到 OP 中记录的相同错误。

I verified that the ftyp, moov and mdat atoms were in the correct order. It turned out that the problem was the the value of the ftyp field. It was set to 'qt '. I used MP4Box to extract the tracks and create a new mp4 file which had the ftyp set to 'isom'. This new file worked fine for Progressive HTTP.

我验证了 ftyp、moov 和 mdat 原子的顺序正确。原来问题出在ftyp字段的值上。它被设置为'qt'。我使用 MP4Box 来提取曲目并创建一个新的 mp4 文件,该文件将 ftyp 设置为“isom”。这个新文件适用于渐进式 HTTP。

回答by MattMatt

I resolved this similarly to the way stated in @nam-trung's answer, however as my videos were already h264and mp4all I needed to do was run the following on each file:

我以类似于@nam-trung 的回答中所述的方式解决了这个问题,但是由于我的视频已经是h264mp4,所以我需要做的就是在每个文件上运行以下内容:

ffmpeg -i input.mp4 -vprofile baseline output.mp4

After that, the videos all worked in VideoViewwhen run on all devices I've tested on running API v19 through v25.

之后,当我在运行 API v19 到 v25 时测试过的所有设备上运行时,这些视频都可以在VideoView 中运行。

回答by droiding

In my case the error was due to the mediaplayer not having file permissions on the locally stored video. Try storing the video onto the /mnt/sdCARDdirectory.

在我的情况下,错误是由于媒体播放器对本地存储的视频没有文件权限。尝试将视频存储到/mnt/sdCARD目录中。

回答by sharma_kunal

I was facing the same issue ,But what i did on my side is

我面临同样的问题,但我所做的是

Firstly i stop the media player and then Released it.

首先我停止媒体播放器,然后释放它。

mMediaPlayer.stop(); mMediaPlayer.release();

mMediaPlayer.stop(); mMediaPlayer.release();

回答by Lee Hounshell

In my case, this problem was caused by a media URL with spaces! Here is the fix:

就我而言,此问题是由带有空格的媒体 URL 引起的!这是修复:

mMediaPlayer.setDataSource(source.replaceAll(" ", "%20"));