• 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

     

  • 相关阅读:
    浏览器兼容性
    Php Ajax 跨域问题
    $.ajax()验证登录
    ajax基础知识总结
    Highcharts获取json数据展现饼图 (转)
    (CV学习笔记)梯度下降优化算法
    (CV学习笔记)Attention
    (数学建模)线性规划
    NumPy中文文档搬砖(划掉)学习笔记(1)
    微机原理作业1微机基础
  • 原文地址:https://www.cnblogs.com/pengmn/p/10064517.html
Copyright © 2020-2023  润新知