Android mp4媒体文件无法播放

时间:2014-07-17 12:07:29

标签: android ffmpeg media android-videoview mp4

我遇到与here相同的问题,我认为是因为文件(在iOS上录制)编码为.mov而不是.mp4。

然后我改变了iOS应用程序的编码机制,将它们编码为mp4,我仍然看到同样的问题。

当我用

加载文件时
File videoFile = ...;
videoView.setVideoPath(videoFile.getAbsolutePath());
videoView.start();

我得到E/MediaPlayer(2069): error (1, -2147483648)

当我使用以下内容加载文件时(来自上面的链接)。

Uri uri = Uri.parse(VideoProvider.CONTENT_URI_BASE + Uri.encode(videoFile.getAbsolutePath()));
videoView.setVideoURL(url);
videoView.start();

我在logcat中得到了这个

07-17 08:05:58.283: W/VideoView(2276): Unable to open content: content://com.companyname.VideoProvider.files.files/%2Fdata%2Fdata%2Fcom.companyname.myappname%2Fcache%2FiX0mXVPxih.mp4
07-17 08:05:58.283: W/VideoView(2276): java.io.IOException: setDataSource failed.: status=0x80000000

ffmpeg告诉我有关媒体文件的以下内容:

ffmpeg -i media.mp4
ffmpeg version 2.2 Copyright (c) 2000-2014 the FFmpeg developers
built on Mar 26 2014 15:29:01 with Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      52. 66.100 / 52. 66.100
  libavcodec     55. 52.102 / 55. 52.102
  libavformat    55. 33.100 / 55. 33.100
  libavdevice    55. 10.100 / 55. 10.100
  libavfilter     4.  2.100 /  4.  2.100
  libavresample   1.  2.  0 /  1.  2.  0
  libswscale      2.  5.102 /  2.  5.102
  libswresample   0. 18.100 /  0. 18.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'media.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp41mp42isom
    creation_time   : 2014-07-17 08:59:24
  Duration: 00:00:08.14, start: 0.000000, bitrate: 1084 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 360x480, 1027 kb/s, 24.46 fps, 29.97 tbr, 600 tbn, 1200 tbc (default)
    Metadata:
      creation_time   : 2014-07-17 08:59:24
      handler_name    : Core Media Video
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 62 kb/s (default)
      Metadata:
        creation_time   : 2014-07-17 08:59:24
        handler_name    : Core Media Audio

知道为什么这个文件可能无法加载?

编辑:在模拟器中运行时,这似乎主要是一个问题,但在设备上,如果我使用SurfaceViewMediaPlayer而不是{我似乎已经成功了它{1}}。

1 个答案:

答案 0 :(得分:0)

您确定该设备上确实存在该文件吗?如果您还没有,可以尝试以下方法:

File videoFile = ...;
if(videoFile.exists){
   videoView.setVideoPath(videoFile.getAbsolutePath());
   videoView.start();
}else{
   Log.e("Video file not found :(!");
}