0

My VideoViewer will not play any MKV files. I've tested on .3gp video files and they work fine but MKV files won't work. The video never shows up, no buffering or anything. The screen will show up fine but as I said, the video player is either invisible or isn't there, I can't tell. In the output, it will say something along the lines of:

connect to ........
new range: ........

and repeat them over and over depending on how big the MKV is. It'll then either make the application stop responding or give the following output.

The output is:

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)

My code: (Not the main activity)

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;
          }

    }
}
Fritz
  • 1
  • 1
  • 2

2 Answers2

2

MKV is not a supported media container under Android.

The supported video file types (container formats) are: .3gp, .mp4 and .webm. There are also restrictions on supported video codecs.

Also, video codec format (h263, h264, mpeg-4, vp8) and container format (3gp, mp4, webm) are two different things. Which means that even if you have a .mp4 file it does not mean Android will be able to play it. It's content would also need to be encoded with a supported codec.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • I thought MKV can be played by installing a codec? I know the linux kernal supports it. –  Sep 25 '11 at 20:23
  • Erm, how do the media player apps play MKV files then? I don't quite understand. – Fritz Sep 26 '11 at 00:52
  • They inpack the mkv container, which can contain multiple streams (video, audio, subtitles), then feed this streams to appropriate codecs, depending on what kind of stream it is. If a codec is missing then sometimes you get no video or no audio. – Peter Knego Sep 26 '11 at 05:27
  • Long story short: you can not play mkv files on Android as it's MediaPlayer does not support that format. You will have to write your own media player or use one of the existing open source players like VLC or MPlayer. – Peter Knego Sep 26 '11 at 05:36
0

Since Android 4.0+, MKV videos are supported as described here. But as @Peter Knego said, video codec format and container format are two different things.

The Android Media API seems to be poorly documented (or at least it was at question time), as other guys have already pointed here. However, using tips from this post and this answer I was able to retrieve both information from two sample videos:

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));

From two different MKV videos, I got the following outputs:

D/VideoActivity: CODEC: video/mp4v-es
D/VideoActivity: CONTAINER: video/x-matroska

D/VideoActivity: CODEC: video/avc
D/VideoActivity: CONTAINER: video/x-matroska

Although I think the best approach to handle unsupported files might be using try/catch blocks and/or VideoView.setOnErrorListening (doc & example), someone could use above methods to extract more details of media before playing it or at least to log what happened if something went wrong.

Perazzo
  • 1,127
  • 13
  • 24