Android VideoView不会播放MKV文件

发布于 2024-12-06 12:13:08 字数 10146 浏览 0 评论 0 原文

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

    }
}

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

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七度光 2024-12-13 12:13:08

MKV 不是 Android 下支持的媒体容器。

支持的视频文件类型(容器格式)为:.3gp、.mp4 和 .webm。支持的视频编解码器也有限制。

此外,视频编解码器格式(h263、h264、mpeg-4、vp8)和容器格式(3gp、mp4、webm)是两个不同的东西。这意味着即使您有 .mp4 文件,也不意味着 Android 能够播放它。其内容还需要使用支持的编解码器进行编码。

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.

执手闯天涯 2024-12-13 12:13:08

自 Android 4.0+ 起,支持 MKV 视频,如此处所述。但正如 @Peter Knego 所说,视频编解码器格式和容器格式是两个不同的东西。

Android Media API 似乎记录很少(或者至少在提问时),正如其他人已经指出的这里。但是,使用这篇文章这个答案 我能够从两个示例视频中检索这两个信息:

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 & 示例),有人可以使用上述方法在播放之前提取媒体的更多详细信息,或者至少记录发生了什么情况出了问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文