我的VideoViewer不会播放任何MKV文件。我已经测试了.3gp视频文件,它们工作正常,但MKV文件无法正常工作。视频从不显示,没有缓冲或任何东西。屏幕显示正常,但正如我所说,视频播放器要么隐形,要么不存在,我无法分辨。在输出中,它会说出以下内容:
connect to ........
new range: ........
并根据MKV的大小重复一遍又一遍。然后,它将使应用程序停止响应或提供以下输出。
输出结果为:
09-25 07:54:40.767: INFO/ActivityManager(68): Starting: Intent { cmp=com.anime/.VideoPlayer } from pid 336
09-25 07:54:41.227: DEBUG/MediaPlayer(336): Couldn't open file on client side, trying server side
09-25 07:54:41.237: INFO/StagefrightPlayer(34): setDataSource('http://pbgl.net/Android/Naruto%20Shippuden/Hun_subtitle_sample1.mkv')
09-25 07:54:41.237: INFO/NuHTTPDataSource(34): connect to pbgl.net:80/Android/Naruto%20Shippuden/Hun_subtitle_sample1.mkv @0
09-25 07:54:41.767: INFO/ActivityManager(68): Displayed com.anime/.VideoPlayer: +968ms
09-25 07:54:43.017: INFO/NuCachedSource2(34): new range: offset= 821676
09-25 07:54:43.017: INFO/NuHTTPDataSource(34): connect to pbgl.net:80/Android/Naruto%20Shippuden/Hun_subtitle_sample1.mkv @821676
09-25 07:54:43.954: INFO/NuCachedSource2(34): new range: offset= 959025
09-25 07:54:43.954: INFO/NuHTTPDataSource(34): connect to pbgl.net:80/Android/Naruto%20Shippuden/Hun_subtitle_sample1.mkv @959025
09-25 07:54:45.564: INFO/NuCachedSource2(34): new range: offset= 1173410
09-25 07:54:45.564: INFO/NuHTTPDataSource(34): connect to pbgl.net:80/Android/Naruto%20Shippuden/Hun_subtitle_sample1.mkv @1173410
09-25 07:54:46.126: INFO/NuCachedSource2(34): ERROR_END_OF_STREAM
09-25 07:54:46.266: INFO/DEBUG(31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
09-25 07:54:46.266: INFO/DEBUG(31): Build fingerprint: 'generic/sdk/generic:2.3.3/GRI34/101070:eng/test-keys'
09-25 07:54:46.266: INFO/DEBUG(31): pid: 34, tid: 345 >>> /system/bin/mediaserver <<<
09-25 07:54:46.266: INFO/DEBUG(31): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000024
09-25 07:54:46.266: INFO/DEBUG(31): r0 00000000 r1 00000008 r2 00000003 r3 000151c0
09-25 07:54:46.266: INFO/DEBUG(31): r4 0000fac0 r5 00014fb0 r6 00000000 r7 a30638bc
09-25 07:54:46.266: INFO/DEBUG(31): r8 a2f60ab1 r9 0000f444 10 00100000 fp 00000001
09-25 07:54:46.266: INFO/DEBUG(31): ip afc01100 sp 40606d58 lr a2ff0fd3 pc a2ff2b78 cpsr 40000030
09-25 07:54:46.426: INFO/DEBUG(31): #00 pc 000f2b78 /system/lib/libstagefright.so
09-25 07:54:46.426: INFO/DEBUG(31): #01 pc 000f0fce /system/lib/libstagefright.so
09-25 07:54:46.426: INFO/DEBUG(31): #02 pc 000f140e /system/lib/libstagefright.so
09-25 07:54:46.436: INFO/DEBUG(31): #03 pc 00054624 /system/lib/libstagefright.so
09-25 07:54:46.436: INFO/DEBUG(31): #04 pc 00046290 /system/lib/libstagefright.so
09-25 07:54:46.436: INFO/DEBUG(31): #05 pc 00047f08 /system/lib/libstagefright.so
09-25 07:54:46.436: INFO/DEBUG(31): #06 pc 00044ea8 /system/lib/libstagefright.so
09-25 07:54:46.436: INFO/DEBUG(31): #07 pc 00060a7e /system/lib/libstagefright.so
09-25 07:54:46.436: INFO/DEBUG(31): #08 pc 00060acc /system/lib/libstagefright.so
09-25 07:54:46.436: INFO/DEBUG(31): #09 pc 00011a7c /system/lib/libc.so
09-25 07:54:46.446: INFO/DEBUG(31): #10 pc 00011640 /system/lib/libc.so
09-25 07:54:46.446: INFO/DEBUG(31): code around pc:
09-25 07:54:46.446: INFO/DEBUG(31): a2ff2b58 685cd104 d101428c e0031c18 42933318
09-25 07:54:46.446: INFO/DEBUG(31): a2ff2b68 2000d1f4 46c0bd70 47706a00 47706b00
09-25 07:54:46.446: INFO/DEBUG(31): a2ff2b78 47706a40 600b6ac3 47706a80 47702001
09-25 07:54:46.446: INFO/DEBUG(31): a2ff2b88 47702000 47702000 47702000 47702000
09-25 07:54:46.446: INFO/DEBUG(31): a2ff2b98 6d591c03 47706d00 6dd91c03 47706d80
09-25 07:54:46.446: INFO/DEBUG(31): code around lr:
09-25 07:54:46.446: INFO/DEBUG(31): a2ff0fb0 fd4cf001 1c2b4f76 447f3308 90079306
09-25 07:54:46.446: INFO/DEBUG(31): a2ff0fc0 e0cb2300 98079904 fe26f001 f0011c06
09-25 07:54:46.446: INFO/DEBUG(31): a2ff0fd0 a909fdd3 1c309003 fdd0f001 201c9005
09-25 07:54:46.446: INFO/DEBUG(31): a2ff0fe0 ebb0f74d f7631c04 9408ff6f d0032c00
09-25 07:54:46.446: INFO/DEBUG(31): a2ff0ff0 a9081c20 eba0f74d f0011c30 2801fd97
09-25 07:54:46.446: INFO/DEBUG(31): stack:
09-25 07:54:46.446: INFO/DEBUG(31): 40606d18 000154c8 [heap]
09-25 07:54:46.446: INFO/DEBUG(31): 40606d1c afc009cf /system/lib/libstdc++.so
09-25 07:54:46.446: INFO/DEBUG(31): 40606d20 000154c8 [heap]
09-25 07:54:46.446: INFO/DEBUG(31): 40606d24 a8114ba7 /system/lib/libutils.so
09-25 07:54:46.446: INFO/DEBUG(31): 40606d28 0000fac0 [heap]
09-25 07:54:46.446: INFO/DEBUG(31): 40606d2c 000154c8 [heap]
09-25 07:54:46.446: INFO/DEBUG(31): 40606d30 a3060eb0 /system/lib/libstagefright.so
09-25 07:54:46.446: INFO/DEBUG(31): 40606d34 a8114ca9 /system/lib/libutils.so
09-25 07:54:46.446: INFO/DEBUG(31): 40606d38 00000002
09-25 07:54:46.446: INFO/DEBUG(31): 40606d3c 40606d78
09-25 07:54:46.446: INFO/DEBUG(31): 40606d40 00014fb0 [heap]
09-25 07:54:46.446: INFO/DEBUG(31): 40606d44 000154f0 [heap]
09-25 07:54:46.446: INFO/DEBUG(31): 40606d48 a30638bc /system/lib/libstagefright.so
09-25 07:54:46.446: INFO/DEBUG(31): 40606d4c a2f42a4d /system/lib/libstagefright.so
09-25 07:54:46.446: INFO/DEBUG(31): 40606d50 df002777
09-25 07:54:46.446: INFO/DEBUG(31): 40606d54 e3a070ad
09-25 07:54:46.446: INFO/DEBUG(31): #01 40606d58 00000004
09-25 07:54:46.446: INFO/DEBUG(31): 40606d5c 00000000
09-25 07:54:46.446: INFO/DEBUG(31): 40606d60 00000004
09-25 07:54:46.446: INFO/DEBUG(31): 40606d64 000152b0 [heap]
09-25 07:54:46.446: INFO/DEBUG(31): 40606d68 00000002
09-25 07:54:46.446: INFO/DEBUG(31): 40606d6c 00000000
09-25 07:54:46.446: INFO/DEBUG(31): 40606d70 00014fb8 [heap]
09-25 07:54:46.446: INFO/DEBUG(31): 40606d74 00015198 [heap]
09-25 07:54:46.446: INFO/DEBUG(31): 40606d78 0000fac0 [heap]
09-25 07:54:46.446: INFO/DEBUG(31): 40606d7c 00000000
09-25 07:54:46.457: INFO/DEBUG(31): 40606d80 000152f0 [heap]
09-25 07:54:46.457: INFO/DEBUG(31): 40606d84 40606da0
09-25 07:54:46.457: INFO/DEBUG(31): 40606d88 00014fb0 [heap]
09-25 07:54:46.457: INFO/DEBUG(31): 40606d8c 00000000
09-25 07:54:46.457: INFO/DEBUG(31): 40606d90 40606e74
09-25 07:54:46.457: INFO/DEBUG(31): 40606d94 a2ff1413 /system/lib/libstagefright.so
09-25 07:54:47.646: WARN/MediaMetadataRetriever(260): MediaMetadataRetriever server died!
09-25 07:54:47.646: WARN/AudioSystem(124): AudioFlinger server died!
09-25 07:54:47.646: WARN/AudioSystem(124): AudioPolicyService server died!
09-25 07:54:47.646: WARN/AudioSystem(336): AudioFlinger server died!
09-25 07:54:47.646: WARN/IMediaDeathNotifier(336): media server died
09-25 07:54:47.646: ERROR/MediaPlayer(336): error (100, 0)
09-25 07:54:47.646: ERROR/MediaPlayer(336): Error (100,0)
09-25 07:54:47.646: DEBUG/VideoView(336): Error: 100,0
09-25 07:54:47.666: WARN/AudioSystem(68): AudioFlinger server died!
09-25 07:54:47.666: WARN/AudioSystem(68): AudioPolicyService server died!
09-25 07:54:47.666: INFO/ServiceManager(28): service 'media.audio_flinger' died
09-25 07:54:47.666: INFO/ServiceManager(28): service 'media.audio_policy' died
09-25 07:54:47.666: INFO/ServiceManager(28): service 'media.player' died
09-25 07:54:47.666: INFO/ServiceManager(28): service 'media.camera' died
09-25 07:54:47.666: INFO/BootReceiver(68): Copying /data/tombstones/tombstone_04 to DropBox (SYSTEM_TOMBSTONE)
09-25 07:54:49.166: ERROR/AudioService(68): Media server died.
09-25 07:54:49.166: INFO/ServiceManager(68): Waiting for service media.audio_flinger...
09-25 07:54:49.977: INFO/(348): ServiceManager: 0xad50
09-25 07:54:49.977: DEBUG/AudioHardwareInterface(348): setMode(NORMAL)
09-25 07:54:49.977: INFO/CameraService(348): CameraService started (pid=348)
09-25 07:54:49.977: INFO/AudioFlinger(348): AudioFlinger's thread 0xc658 ready to run
09-25 07:54:50.198: ERROR/AudioService(68): Media server started.
09-25 07:54:50.207: DEBUG/AudioHardwareInterface(348): setMode(NORMAL)
我的代码:(不是主要活动)
package com.anime;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import android.app.*;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.*;
import android.text.*;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import android.widget.AdapterView.OnItemClickListener;
public class VideoPlayer extends Activity implements OnClickListener {
/** Called when the activity is first created. */
VideoView vv;
Button close;
public static String selectedVideo = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vidplayer);
close = (Button) findViewById(R.id.button1);
vv = (VideoView) findViewById(R.id.videoView1);
playVideo(selectedVideo);
View btn1 = findViewById(R.id.button1);
btn1.setOnClickListener(this);
}
public void playVideo(String selected) {
setContentView(R.layout.vidplayer);
String url = RunApp.videoUrls.get(RunApp.currentShow).get(RunApp.videos.get(RunApp.currentShow).indexOf(selected)).toString(); // your URL here
vv = (VideoView) findViewById(R.id.videoView1);
try {
vv.setVideoURI(Uri.parse(url));
vv.setMediaController(new MediaController(this));
vv.requestFocus();
vv.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onClick(View v) {
System.out.println("ID: " + v.getId());
switch (v.getId()){
case R.id.button1:
finish();
break;
}
}
}
答案 0 :(得分:2)
MKV不是Android下的supported media容器。
支持的视频文件类型(容器格式)为:.3gp,.mp4和.webm。支持的视频编解码器也有限制。
此外,视频编解码器格式(h263,h264,mpeg-4,vp8)和容器格式(3gp,mp4,webm)是两回事。这意味着,即使你有.mp4文件,也不意味着Android可以播放它。它的内容也需要使用支持的编解码器进行编码。
答案 1 :(得分:0)
自Android 4.0及以上版本支持MKV视频here。但正如@Peter Knego所说,视频编解码格式和容器格式是两回事。
Android Media API似乎记录不佳(或至少在问题时间),因为其他人已经指出here。但是,使用this post和this answer中的提示,我能够从两个示例视频中检索这两种信息:
Uri videoUri = Uri.parse("android.resource://"
+ getPackageName() + "/" + R.raw.sample_video);
// Codec Format
extractor = new MediaExtractor();
extractor.setDataSource(this, videoUri, null);
for (int i = 0; i < extractor.getTrackCount(); i++) {
MediaFormat format = extractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (mime.startsWith("video/")) {
Log.d(TAG, "CODEC: " + mime);
break;
}
}
// Container Format
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(this, videoUri);
Log.d(TAG, "CONTAINER: "
+ mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE));
从两个不同的MKV视频中,我得到了以下输出:
D/VideoActivity: CODEC: video/mp4v-es
D/VideoActivity: CONTAINER: video/x-matroska
D/VideoActivity: CODEC: video/avc
D/VideoActivity: CONTAINER: video/x-matroska
虽然我认为处理不受支持的文件的最佳方法可能是使用try/catch
阻止和/或VideoView.setOnErrorListening
(doc&amp; example),但有人可以使用上述方法在播放之前提取更多媒体细节,或者至少记录出现问题时发生的事情。