码迷,mamicode.com
首页 > 其他好文 > 详细

ijkplayer实现IMediaDataSource

时间:2018-12-04 17:11:01      阅读:332      评论:0      收藏:0      [点我收藏+]

标签:html   resource   dia   nts   data   puts   exce   setfile   文件的   

 

由于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

标签:html   resource   dia   nts   data   puts   exce   setfile   文件的   

原文地址:https://www.cnblogs.com/pengmn/p/10064517.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!