ijkplayer实现IMediaDataSource
Posted pengmn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ijkplayer实现IMediaDataSource相关的知识,希望对你有一定的参考价值。
由于ijkplayer不能识别android.resource类型的资源在播放raw中的文件的时候用IjkMediaPlayer不能正常播放,实现IMediaDataSource为IjkMediaPlayer提供资源。 class RawDataSourceProvider implements IMediaDataSource{ AssetFileDescriptor mDescriptor; byte[] mMediaBytes; long mPosition; public RawDataSourceProvider(AssetFileDescriptor descriptor) { this.mDescriptor = descriptor; } @Override public int readAt(long position, byte[] buffer, int offset, int size) throws IOException { if(position + 1 >= mMediaBytes.length){ return -1; } int length; if(position + size < mMediaBytes.length){ length = size; }else{ length = (int) (mMediaBytes.length - position); if(length > buffer.length) length = buffer.length ; length--; } System.arraycopy(mMediaBytes, (int) position, buffer, offset, length); mPosition = position; return length; } @Override public long getSize() throws IOException { long length = mDescriptor.getLength(); if(mMediaBytes == null){ Source source = Okio.source(mDescriptor.createInputStream()); mMediaBytes = Okio.buffer(source).readByteArray(); } return length; } @Override public void close() throws IOException { if(mDescriptor != null) mDescriptor.close(); mDescriptor = null; mMediaBytes = null; } } https://www.cnblogs.com/xwgblog/p/5287151.html
以上是关于ijkplayer实现IMediaDataSource的主要内容,如果未能解决你的问题,请参考以下文章
基于 IJKPlayer-concat 协议的视频无缝拼接技术实现
直播技术总结ijkplayer的编译到Android平台并测试解码库
ijkplayer编译 Android 版本的 ijkplayer ① ( Ubuntu 安装 Git 软件 | 下载 ijkplayer 代码 )