Java Code Examples for tv.danmaku.ijk.media.player.IjkMediaPlayer#setOption()

The following examples show how to use tv.danmaku.ijk.media.player.IjkMediaPlayer#setOption() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IjkPlayer.java    From VideoDemoJava with MIT License 6 votes vote down vote up
private IjkMediaPlayer createPlayer() {
        IjkMediaPlayer ijkMediaPlayer = new IjkMediaPlayer();
//        ijkMediaPlayer.native_setLogLevel(IjkMediaPlayer.IJK_LOG_DEBUG);

        //open mediacodec
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 1);

        //accurate seek
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", 1);

        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", 1);
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "opensles", 1);
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 1);
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0);

        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", 10000000);
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "reconnect", 1);

        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "http-detect-range-support", 0);

        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48);
        return ijkMediaPlayer;
    }
 
Example 2
Source File: IjkPlayerImpl.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public IjkPlayerImpl(Context context, PlayerAttributes attributes) {
    super(context, attributes);

    mPlayer = new IjkMediaPlayer();

    //不用MediaCodec编解码
    mPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,
        "mediacodec", 1);

    //不用opensles编解码
    mPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,
        "opensles", 0);
    mPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,
        "overlay-format", IjkMediaPlayer.SDL_FCC_RV32);
    mPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,
            "framedrop", 1);
    mPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,
        "start-on-prepared", 0);
    mPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,
        "http-detect-range-support", 0);
    mPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,
        "timeout", 10000000);
    mPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,
        "reconnect", 1);
    mPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC,
        "skip_loop_filter", 48);
    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    initPlayerListeners();
}
 
Example 3
Source File: XMediaPlayer.java    From XPlayer2 with Apache License 2.0 5 votes vote down vote up
private IjkMediaPlayer createPlayer() {
        IjkMediaPlayer ijkMediaPlayer = new IjkMediaPlayer();
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 0); // 软解码
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "opensles", 0);
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", IjkMediaPlayer.SDL_FCC_RV32);

        // 音视频不同步问题:framedrop 控制着允许丢帧的范围。可以通过修改 framedrop 的数值来解决不同步的问题,
        // framedrop是在视频帧处理不过来的时候丢弃一些帧达到同步的效果。
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 1);
        // 准备完成后,自动开始播放
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 1);

        // IJKMEDIA: Option ijkiomanager not found.
        // IJKMEDIA: Option http-detect-range-support not found.
//        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "http-detect-range-support", 0);
//        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48);

        ijkMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        ijkMediaPlayer.setScreenOnWhilePlaying(true);
        ijkMediaPlayer.setOnNativeInvokeListener(new IjkMediaPlayer.OnNativeInvokeListener() {
            @Override
            public boolean onNativeInvoke(int i, Bundle bundle) {
                return true;
            }
        });

        ijkMediaPlayer.setOnPreparedListener(this);
        ijkMediaPlayer.setOnVideoSizeChangedListener(this);
        ijkMediaPlayer.setOnInfoListener(this);
        ijkMediaPlayer.setOnBufferingUpdateListener(this);
        ijkMediaPlayer.setOnSeekCompleteListener(this);
        ijkMediaPlayer.setOnCompletionListener(this);
        ijkMediaPlayer.setOnErrorListener(this);

        // 开启调试的LOG
        IjkMediaPlayer.native_setLogLevel(IjkMediaPlayer.IJK_LOG_DEBUG);
        return ijkMediaPlayer;
    }
 
Example 4
Source File: IjkVideoView.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
public void setSpeed(float speed) {
    if (mIsUsingPlayerType == Constants.IJK_PLAYER) {
        IjkMediaPlayer ijkMediaPlayer = (IjkMediaPlayer) mMediaPlayer;
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "soundtouch", 1);
        ijkMediaPlayer.setSpeed(speed);
        mMediaPlayer.start();
    }
}
 
Example 5
Source File: PlayerView.java    From VRPlayer with Apache License 2.0 5 votes vote down vote up
private void enableHardwareDecoding() {
    if (mMediaPlayer instanceof IjkMediaPlayer) {
        IjkMediaPlayer player = (IjkMediaPlayer) mMediaPlayer;
        player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 1);
        player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", 1);
        player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", IjkMediaPlayer.SDL_FCC_RV32);
        player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 60);
        player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-fps", 0);
        player.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48);
    }
}
 
Example 6
Source File: IjkPlayer.java    From PlayerBase with Apache License 2.0 5 votes vote down vote up
protected IjkMediaPlayer createPlayer(){
        IjkMediaPlayer ijkMediaPlayer = new IjkMediaPlayer();
//        ijkMediaPlayer.native_setLogLevel(IjkMediaPlayer.IJK_LOG_DEBUG);

        //设置清除dns cache
        //IjkMediaPlayer.OPT_CATEGORY_FORMAT, "dns_cache_clear", 1

        //open mediacodec
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 1);
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-hevc", 1);

        //accurate seek
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", 1);

        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", 1);
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "opensles", 1);
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 1);
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0);

        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", 10000000);
        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "reconnect", 1);

        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "http-detect-range-support", 0);

        ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48);
        return ijkMediaPlayer;
    }
 
Example 7
Source File: ParsingPlayer.java    From ParsingPlayer with GNU Lesser General Public License v2.1 5 votes vote down vote up
private IjkMediaPlayer createPlayer(Config config) {
    IjkMediaPlayer ijkMediaPlayer = new IjkMediaPlayer();
    IjkMediaPlayer.loadLibrariesOnce(null);
    IjkMediaPlayer.native_profileBegin("libijkplayer.so");
    IjkMediaPlayer.native_setLogLevel(BuildConfig.DEBUG ? IjkMediaPlayer.IJK_LOG_DEFAULT : IjkMediaPlayer.IJK_LOG_ERROR);
    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,
            "safe", config.safe ? 1 : 0);
    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,
            "protocol_whitelist", config.whiteList);
    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,
            "mediacodec-auto-rotate", config.mediacodecAutoRotate ? 1 : 0);
    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,
            "mediacodec-handle-resolution-change", config.mediacodecHandleResolutionChange ? 1 : 0);
    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,
            "opensles", config.opensles ? 1 : 0);
    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,
            "overlay-format", config.overLayFormat);
    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,
            "framedrop", config.frameDrop ? 1 : 0);
    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,
            "start-on-prepared", config.startOnPrepared ? 1 : 0);
    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,
            "http-detect-range-support", config.httpRangeSupport ? 1 : 0);
    ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC,
            "skip_loop_filter", config.skipLoopFilter);
    return ijkMediaPlayer;
}
 
Example 8
Source File: IjkPlayerManager.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
private void initIJKOption(IjkMediaPlayer ijkMediaPlayer, List<VideoOptionModel> optionModelList) {
    if (optionModelList != null && optionModelList.size() > 0) {
        for (VideoOptionModel videoOptionModel : optionModelList) {
            if (videoOptionModel.getValueType() == VideoOptionModel.VALUE_TYPE_INT) {
                ijkMediaPlayer.setOption(videoOptionModel.getCategory(),
                        videoOptionModel.getName(), videoOptionModel.getValueInt());
            } else {
                ijkMediaPlayer.setOption(videoOptionModel.getCategory(),
                        videoOptionModel.getName(), videoOptionModel.getValueString());
            }
        }
    }
}
 
Example 9
Source File: MediaPlayerWrapper.java    From MD360Player4Android with Apache License 2.0 5 votes vote down vote up
private void enableHardwareDecoding(){
    if (mPlayer instanceof IjkMediaPlayer){
        IjkMediaPlayer player = (IjkMediaPlayer) mPlayer;
        player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 1);
        player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", 1);
        player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", IjkMediaPlayer.SDL_FCC_RV32);
        player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 60);
        player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-fps", 0);
        player.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48);
    }
}
 
Example 10
Source File: IjkMedia.java    From QSVideoPlayer with Apache License 2.0 4 votes vote down vote up
@Override
    IMediaPlayer getMedia(Context context, String url, Map<String, String> headers, Object... objects) throws Exception {
        IjkMediaPlayer mediaPlayer = new IjkMediaPlayer();

        if (url.startsWith(ContentResolver.SCHEME_CONTENT) || url.startsWith(ContentResolver.SCHEME_ANDROID_RESOURCE))
            mediaPlayer.setDataSource(context, Uri.parse(url), headers);
        else
            mediaPlayer.setDataSource(url, headers);


        if (objects != null && objects.length > 0 && objects[0] instanceof List) {
            List<Option> list = (List<Option>) objects[0];
            for (Option o : list) {
                if (o.strValue != null)
                    mediaPlayer.setOption(o.category, o.name, o.strValue);
                else
                    mediaPlayer.setOption(o.category, o.name, o.longValue);
            }
        }

        //mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "soundtouch", 1);

//        if (mSettings.getUsingMediaCodec()) {
//            mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 1);
//            if (mSettings.getUsingMediaCodecAutoRotate()) {
//                mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", 1);
//            } else {
//                mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", 0);
//            }
//        } else {
//            mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 0);
//        }
//
//        if (mSettings.getUsingOpenSLES()) {
//            mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "opensles", 1);
//        } else {
//            mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "opensles", 0);
//        }
//
//        String pixelFormat = mSettings.getPixelFormat();
//        if (TextUtils.isEmpty(pixelFormat)) {
//            mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", IjkMediaPlayer.SDL_FCC_RV32);
//        } else {
//            mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", pixelFormat);
//        }
//        mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 1);
//        mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0);
//
//        mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "http-detect-range-support", 0);
//
//        mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48);
        return mediaPlayer;
    }