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

huangapple go评论93阅读模式
英文:

Unable to play MKV Matroska video with exoPlayer 2.11

问题

在我的视频播放器中,当我尝试播放 MKV Matroska 文件时,视频保持静止,无法播放。

我按照 CodeLabsExoPlayer 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);
    }
}

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

我甚至尝试了以下方法:

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

在 Logcat 中,我看到了以下错误:

E/ACodec: [OMX.google.hevc.decoder] setPortMode on output to DynamicANWBuffer failed w/ err -1010

编辑:

经过多次研究,我尝试了以下内容:https://github.com/sanoj26692/pay/blob/master/player

这是我尝试以离线模式播放的文件:http://jell.yfish.us/media/jellyfish-3-mbps-hd-h264.mkv

以下是我的 Logcat 日志:

(接下来是一系列的日志记录,包括初始化过程、错误信息等。由于篇幅原因,我无法逐一翻译和解释每条日志记录的含义,但您似乎遇到了关于视频解码的问题。如果您需要进一步的帮助,可以提供更多细节,我将尽力协助您解决问题。)

英文:

In my video player when i try to play MKV Matroska file it stay still the video is not playing.

i followed CodeLabs and ExoPlayer Dev and build player it can play .MP4 but unable to play .MKV

here is my player:(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);
    }
}

Show how should i play MKV video using exoplayer. All files are local files from storage.

I even tried following method:

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

In logcat i see this error:

> 2826-3120/com.example.jlplayer E/ACodec: [OMX.google.hevc.decoder] setPortMode on output to DynamicANWBuffer failed w/ err -1010

> EDIT:

after multiple research here is what i tried https://github.com/sanoj26692/pay/blob/master/player

here is the file am trying to play in offline mode. http://jell.yfish.us/media/jellyfish-3-mbps-hd-h264.mkv

and here is my logcat:

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  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]

答案1

得分: 3

我在Github上创建了一个示例项目,可以正确地与你的文件一起使用。你可以在下面的链接中查看并测试它:

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

如果你只想在你的项目中使用这些代码,请首先卸载你设备或模拟器上之前安装的应用程序,然后运行新的应用程序。

以下是项目的关键代码部分:

MainActivity.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文件夹中,但你可以根据需要更改它。

英文:

I made a sample project on Github that works properly with your file. You can check and test it in the link below:

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

If you just want to use the codes in your project, first uninstall the previously installed app from your device or emulator and then run the new one.

Here are the essential codes of the project:

> 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(&quot;file:///android_asset/jellyfish-3-mbps-hd-h264.mkv&quot;));
player.prepare(mediaSource);
player.setPlayWhenReady(true);
}
@Override
protected void onStop() {
super.onStop();
playerView.setPlayer(null);
player.release();
}
}

> activity_main.xml

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;&gt;
&lt;com.google.android.exoplayer2.ui.PlayerView
android:id=&quot;@+id/player_view&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:background=&quot;#000000&quot;
app:resize_mode=&quot;fill&quot; /&gt;
&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;

Also, you need to add these dependencies to the app level Gradle file:

implementation &#39;com.google.android.exoplayer:exoplayer-core:2.11.7&#39;
implementation &#39;com.google.android.exoplayer:exoplayer-ui:2.11.7&#39;

I put the video file in the asset folder but you can change it base on your needs.

答案2

得分: -1

尝试按照以下方式创建 MediaSource

private MediaSource buildMediaSource(Uri uri) {
    DataSource.Factory dataSourceFactory =
        new DefaultDataSourceFactory(this, "exoplayer");
    return new ExtractorMediaSource.Factory(dataSourceFactory)
        .createMediaSource(uri);
}
英文:

Try to make MediaSource like this:

private MediaSource buildMediaSource(Uri uri) {
DataSource.Factory dataSourceFactory =
new DefaultDataSourceFactory(this, &quot;exoplayer&quot;);
return new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(uri);
}

huangapple
  • 本文由 发表于 2020年7月26日 22:59:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63101825.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定