当前位置: 首页 > 面试题库 >

无法使用exoPlayer 2.11播放MKV Matroska视频

子车超英
2023-03-14
问题内容

在我的视频播放器中,当我尝试播放MKV Matroska文件时,它仍然不播放视频。

我跟随CodeLabs和ExoPlayer Dev并构建了可以播放.MP4但无法播放的播放器.MKV

这是我的球员:(exoplayer 2.11.5)

private void initializePlayer() {
    if (player == null) {
        player = new SimpleExoPlayer.Builder(this).build();
        playerView.setPlayer(player);
        Uri uri = Uri.parse(String.valueOf(videoUri));
        MediaSource mediaSource = buildMediaSource(uri);
        player.setPlayWhenReady(playWhenReady);
        player.seekTo(currentWindow, playbackPosition);
        player.addListener(playbackStateListener);
        player.prepare(mediaSource, false, false);
    }
}

private MediaSource buildMediaSource(Uri uri) {
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, "exoplayer-codelab");
    @C.ContentType int type = Util.inferContentType(uri);
    switch (type) {
        case C.TYPE_DASH:
            return new DashMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
        case C.TYPE_SS:
            return new SsMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
        case C.TYPE_HLS:
            return new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
        case C.TYPE_OTHER:
            return new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
        default:
            throw new IllegalStateException("Unsupported type: " + type);
    }
}

展示如何MKV使用exoplayer 播放视频。所有文件都是来自存储的本地文件。

我什至尝试了以下方法:

    private MediaSource buildMediaSource(Uri uri) {
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, "exoplayer-codelab") ;
            return new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
    }
}

在logcat中,我看到此错误:

2826-3120 / com.example.jlplayer E / ACodec:[OMX.google.hevc.decoder]
setPortMode输出到DynamicANWBuffer失败,错误-1010

编辑:

经过多次研究后,我尝试了这里https://github.com/sanoj26692/pay/blob/master/player

这是文件正在尝试以脱机模式播放。http://jell.yfish.us/media/jellyfish-3-mbps-
hd-h264.mkv

这是我的日志

2020-08-17 01:36:23.384 10937-10937/com.google.android.exoplayer2.demo V/AudioManager: playSoundEffect   effectType: 0

    --------- beginning of system
2020-08-17 01:36:23.427 10937-10937/com.google.android.exoplayer2.demo D/HwCust: Create obj success use class android.app.HwCustActivityImpl
2020-08-17 01:36:23.430 10937-10937/com.google.android.exoplayer2.demo D/HwCust: Create obj success use class android.app.HwCustHwWallpaperManagerImpl
2020-08-17 01:36:23.432 10937-10937/com.google.android.exoplayer2.demo V/ActivityThread: ActivityThread,callActivityOnCreate
2020-08-17 01:36:23.455 10937-10937/com.google.android.exoplayer2.demo D/HwRTBlurUtils: check blur style for HwPhoneWindow, themeResId : 0x7f1000fc, context : com.google.android.exoplayer2.demo.PlayerActivity@b211450, Nhwext : 0, get Blur : disable with , null
2020-08-17 01:36:23.456 10937-10937/com.google.android.exoplayer2.demo D/HwRTBlurUtils: check blur style for HwPhoneWindow, themeResId : 0x7f1000fc, context : com.google.android.exoplayer2.demo.PlayerActivity@b211450, Nhwext : 0, get Blur : disable with , null
2020-08-17 01:36:23.555 10937-10937/com.google.android.exoplayer2.demo I/ExoPlayerImpl: Init cb3d2e5 [ExoPlayerLib/2.11.7] [HWPRA-H, PRA-AL00X, HUAWEI, 26]
2020-08-17 01:36:23.562 10937-10937/com.google.android.exoplayer2.demo V/AudioManager: registerAudioFocusListener...
2020-08-17 01:36:23.565 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: state [eventTime=0.01, mediaPos=0.00, window=0, true, BUFFERING]
2020-08-17 01:36:23.567 10937-10937/com.google.android.exoplayer2.demo D/ActivityThread: add activity client record, r= ActivityRecord{b53b861 token=android.os.BinderProxy@862c24d {com.google.android.exoplayer2.demo/com.google.android.exoplayer2.demo.PlayerActivity}} token= android.os.BinderProxy@862c24d
2020-08-17 01:36:23.578 10937-10978/com.google.android.exoplayer2.demo D/OpenGLRenderer:   HWUI Binary is  enabled
2020-08-17 01:36:23.581 10937-11127/com.google.android.exoplayer2.demo D/MediaCodecInfo: NoSupport [sizeAndRate.support, 1920x1080x-1.0] [OMX.IMG.MSVDX.Decoder.HEVC, video/hevc] [HWPRA-H, PRA-AL00X, HUAWEI, 26]
2020-08-17 01:36:23.581 10937-10945/com.google.android.exoplayer2.demo I/zygote64: Compiler allocated 5MB to compile void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int)
2020-08-17 01:36:23.583 10937-11127/com.google.android.exoplayer2.demo D/MediaCodecInfo: NoSupport [sizeAndRate.support, 1920x1080x-1.0] [OMX.IMG.MSVDX.Decoder.HEVC, video/hevc] [HWPRA-H, PRA-AL00X, HUAWEI, 26]
2020-08-17 01:36:23.588 10937-11127/com.google.android.exoplayer2.demo D/MediaCodecInfo: NoSupport [sizeAndRate.support, 1920x1080x-1.0] [OMX.IMG.MSVDX.Decoder.HEVC, video/hevc] [HWPRA-H, PRA-AL00X, HUAWEI, 26]
2020-08-17 01:36:23.596 10937-10937/com.google.android.exoplayer2.demo I/PressGestureDetector: onAttached begin
2020-08-17 01:36:23.598 10937-10937/com.google.android.exoplayer2.demo I/PressGestureDetector: onAttached end
2020-08-17 01:36:23.598 10937-11131/com.google.android.exoplayer2.demo I/PressGestureDetector: HiTouch restricted: AboardArea.
2020-08-17 01:36:23.599 10937-11130/com.google.android.exoplayer2.demo I/OMXClient: Treble IOmx obtained
2020-08-17 01:36:23.604 10937-11130/com.google.android.exoplayer2.demo I/ACodec: In onAllocateComponent create compenent, codec name: OMX.google.hevc.decoder
2020-08-17 01:36:23.617 10937-11134/com.google.android.exoplayer2.demo E/BufferQueueProducer: [] Can not get hwsched service
2020-08-17 01:36:23.619 10937-11129/com.google.android.exoplayer2.demo D/SurfaceUtils: connecting to surface 0x7d3548d010, reason connectToSurface
2020-08-17 01:36:23.619 10937-11129/com.google.android.exoplayer2.demo I/MediaCodec: [OMX.google.hevc.decoder] setting surface generation to 11199492
2020-08-17 01:36:23.619 10937-11129/com.google.android.exoplayer2.demo D/SurfaceUtils: disconnecting from surface 0x7d3548d010, reason connectToSurface(reconnect)
2020-08-17 01:36:23.619 10937-11129/com.google.android.exoplayer2.demo D/SurfaceUtils: connecting to surface 0x7d3548d010, reason connectToSurface(reconnect)
2020-08-17 01:36:23.619 10937-11130/com.google.android.exoplayer2.demo W/HwExtendedUtils: hw configLocalPlayBack err = -1010
2020-08-17 01:36:23.620 10937-11130/com.google.android.exoplayer2.demo E/ACodec: [OMX.google.hevc.decoder] setPortMode on output to DynamicANWBuffer failed w/ err -1010
2020-08-17 01:36:23.620 10937-11130/com.google.android.exoplayer2.demo I/HwExtendedCodec: mime is [video/hevc] at setVideoFormat
2020-08-17 01:36:23.623 10937-11130/com.google.android.exoplayer2.demo I/ACodec: codec does not support config priority (err -1010)
2020-08-17 01:36:23.628 10937-11130/com.google.android.exoplayer2.demo I/ACodec: onStart
2020-08-17 01:36:23.656 10937-10978/com.google.android.exoplayer2.demo D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000
2020-08-17 01:36:23.668 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: surfaceSize [eventTime=0.11, mediaPos=0.00, window=0, 1080, 1722]
2020-08-17 01:36:23.714 10937-11129/com.google.android.exoplayer2.demo D/SurfaceUtils: connecting to surface 0x7d33473010, reason connectToSurface
2020-08-17 01:36:23.714 10937-11129/com.google.android.exoplayer2.demo I/MediaCodec: [OMX.google.hevc.decoder] setting surface generation to 11199493
2020-08-17 01:36:23.714 10937-11129/com.google.android.exoplayer2.demo D/SurfaceUtils: disconnecting from surface 0x7d33473010, reason connectToSurface(reconnect)
2020-08-17 01:36:23.714 10937-11129/com.google.android.exoplayer2.demo D/SurfaceUtils: connecting to surface 0x7d33473010, reason connectToSurface(reconnect)
2020-08-17 01:36:23.715 10937-11129/com.google.android.exoplayer2.demo D/SurfaceUtils: disconnecting from surface 0x7d3548d010, reason disconnectFromSurface
2020-08-17 01:36:23.731 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: timeline [eventTime=0.17, mediaPos=0.00, window=0, periodCount=1, windowCount=1, reason=PREPARED
2020-08-17 01:36:23.732 10937-10937/com.google.android.exoplayer2.demo D/EventLogger:   period [?]
2020-08-17 01:36:23.732 10937-10937/com.google.android.exoplayer2.demo D/EventLogger:   window [?, false, false]
2020-08-17 01:36:23.732 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: ]
2020-08-17 01:36:23.756 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: mediaPeriodCreated [eventTime=0.20, mediaPos=0.00, window=0, period=0]
2020-08-17 01:36:23.758 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: loading [eventTime=0.20, mediaPos=0.00, window=0, period=0, true]
2020-08-17 01:36:23.761 10937-10978/com.google.android.exoplayer2.demo D/OpenGLRenderer:   HWUI Binary is  enabled
2020-08-17 01:36:23.762 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: timeline [eventTime=0.20, mediaPos=0.00, window=0, period=0, periodCount=1, windowCount=1, reason=DYNAMIC
2020-08-17 01:36:23.763 10937-10937/com.google.android.exoplayer2.demo D/EventLogger:   period [30.10]
2020-08-17 01:36:23.763 10937-10937/com.google.android.exoplayer2.demo D/EventLogger:   window [30.10, true, false]
2020-08-17 01:36:23.763 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: ]
2020-08-17 01:36:23.787 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: decoderEnabled [eventTime=0.23, mediaPos=0.00, window=0, period=0, video]
2020-08-17 01:36:23.788 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: tracks [eventTime=0.23, mediaPos=0.00, window=0, period=0
2020-08-17 01:36:23.788 10937-10937/com.google.android.exoplayer2.demo D/EventLogger:   Renderer:0 [
2020-08-17 01:36:23.789 10937-10937/com.google.android.exoplayer2.demo D/EventLogger:     Group:0, adaptive_supported=N/A [
2020-08-17 01:36:23.789 10937-10937/com.google.android.exoplayer2.demo D/EventLogger:       [X] Track:0, id=1, mimeType=video/hevc, res=1920x1080, supported=YES
2020-08-17 01:36:23.789 10937-10937/com.google.android.exoplayer2.demo D/EventLogger:     ]
2020-08-17 01:36:23.789 10937-10937/com.google.android.exoplayer2.demo D/EventLogger:   ]
2020-08-17 01:36:23.789 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: ]
2020-08-17 01:36:23.794 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: mediaPeriodReadingStarted [eventTime=0.23, mediaPos=0.00, window=0, period=0]
2020-08-17 01:36:23.795 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: downstreamFormat [eventTime=0.24, mediaPos=0.00, window=0, period=0, id=1, mimeType=video/hevc, res=1920x1080]
2020-08-17 01:36:23.798 10937-10937/com.google.android.exoplayer2.demo W/InputMethodManager: startInputReason = 1
2020-08-17 01:36:23.820 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: decoderInitialized [eventTime=0.26, mediaPos=0.00, window=0, period=0, video, OMX.google.hevc.decoder]
2020-08-17 01:36:23.821 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: decoderInputFormat [eventTime=0.26, mediaPos=0.00, window=0, period=0, video, id=1, mimeType=video/hevc, res=1920x1080]
2020-08-17 01:36:23.828 10937-10978/com.google.android.exoplayer2.demo W/libEGL: EGLNativeWindowType 0x7d37723010 disconnect failed
2020-08-17 01:36:23.828 10937-10978/com.google.android.exoplayer2.demo D/OpenGLRenderer: endAllActiveAnimators on 0x7d55764800 (ExpandableListView) with handle 0x7d5575c9a0
2020-08-17 01:36:24.185 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: loading [eventTime=0.63, mediaPos=0.00, window=0, period=0, false]
2020-08-17 01:36:24.258 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: state [eventTime=0.70, mediaPos=0.00, window=0, period=0, true, READY]
2020-08-17 01:36:24.262 10937-10937/com.google.android.exoplayer2.demo D/EventLogger: isPlaying [eventTime=0.70, mediaPos=0.00, window=0, period=0, true]

问题答案:

我在Github上制作了一个示例项目,该项目可以正确处理您的文件。您可以在下面的链接中进行检查和测试:

https://github.com/squti/ExoPlayer-MKV-
Sample

如果您只想使用项目中的代码,请先从设备或仿真器中卸载以前安装的应用程序,然后运行新的应用程序

以下是项目的基本代码:

MainActiviy.java

public class MainActivity extends AppCompatActivity {

    private PlayerView playerView;
    private SimpleExoPlayer player;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        playerView = findViewById(R.id.player_view);

    }

    @Override
    protected void onStart() {
        super.onStart();
        player = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector());
        playerView.setPlayer(player);

        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(
                this,
                Util.getUserAgent(this, getString(R.string.app_name)));
        ProgressiveMediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
                .createMediaSource(Uri.parse("file:///android_asset/jellyfish-3-mbps-hd-h264.mkv"));

        player.prepare(mediaSource);
        player.setPlayWhenReady(true);
    }

    @Override
    protected void onStop() {
        super.onStop();
        playerView.setPlayer(null);
        player.release();
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/player_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000000"
        app:resize_mode="fill" />

</androidx.constraintlayout.widget.ConstraintLayout>

另外,您需要将以下依赖项添加到应用程序级别的Gradle文件中:

implementation 'com.google.android.exoplayer:exoplayer-core:2.11.7'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.11.7'

我将视频文件放在asset文件夹中,但是您可以根据需要进行更改。



 类似资料:
  • 问题内容: 我正在使用Flask提供.m3u8和.ts文件来模拟vod流。 视频播放器不会流式传输文件并显示错误(请参见下面的屏幕截图)。我找不到它是什么错误的日志。 我缺少某处的日志消息吗?是什么原因造成的,我该如何解决? 问题答案: 默认情况下,开发服务器以单线程模式运行,这意味着它一次只能处理一个请求。你一次请求两个文件流,.m3u8和.ts。你可以传递或以允许一次处理多个请求,但是,用它自

  • 问题内容: 我遵循了一些有关结合JavaFX与Swing(JFrame)来播放视频的教程,但是我得到的只是一个黑屏,该视频应该没有任何实际的内容播放,也没有报错。 我在这里做错什么,为什么不播放视频? 我尝试了几个.flv视频,但都不会开始播放(当我在浏览器中打开它们时,它们会播放) 我在装有K-lite完整编解码器包的Windows 8.1 N Pro上运行jre7和jdk1.7.0_45 编辑

  • 在我的应用程序中,我想显示来自服务器URI路径的视频,在这里,第一次播放视频,当我想第二次播放视频时,视频没有播放,并显示一个弹出窗口,如无法播放此视频 下面是我的错误 提前谢谢。

  • 我收到这个错误“无法加载现代控件UI。升级到Android YouTube API的最新版本。”我使用了youtubePlayer。addFullscreenControlFlag(YouTubePlayer.FULLSCREEN\u FLAG\u CONTROL\u SYSTEM\u UI) 但仍然得到同样的错误也我去无法播放一些YouTube视频使用YouTubeAndroid Player

  • 每当我加载html文件时,它都会给我一个错误 每当我按下播放按钮时,就会出现以下错误 我能够加载任何远程视频并运行,但问题是当我从资产文件夹代码加载本地视频以加载文件并设置web视图时 干杯,Saurav

  • 问题内容: 无法播放此视频错误… !! 看到图片 截屏 怎么办?按下播放按钮后,它说不能播放此视频。需要解决这个问题。 问题答案: 您好,前天我遇到了同样的问题,几乎尝试了所有方法,但都没有成功。之后,我使用了这个库,并且运行良好。只需遵循几个步骤: 第1步。 将其添加到您的gradle 第2步。 将其添加为xml布局中的视频播放。 第3步。 从此处检查如何在您的班级中使用此库, 我这边还有另外一