Skip to content

transition_demo

zanxiaofei edited this page Dec 7, 2017 · 2 revisions

转场功能使用说明

Demo中提供了以下几个类用于完成转场功能的展示

  • MultiImportActivity: 多段导入预览窗口,窗口展示了多个文件的预览及在文件中添加转场后的效果展示
  • TransitionTypeAdapter:转场类型选择器
  • TransitionAdapter:转场位置选择器

以Demo的操作场景为例说明转场设置的操作步骤:

默认demo展示无转场效果 1 选择转场位置

  mTransitionAdapter.setTransitionItemListener(new TransitionAdapter.OnTransitionItemListener() {
            @Override
            public void transitionSelected(int index) {
                //当前去除了片头片尾滤镜,因此需要在index基础上加1
                mTransitionIndex = index + 1;
        });

2 选择转场类型并设置转场type给SDK

mTransitionTypeAdapter.setOnItemClickListener(new TransitionTypeAdapter.OnItemClickListener() {
           @Override
           public void onClick(int curIndex, int preIndex) {
               mTransitionType = curIndex;
               mKSYTransitionsKit.setTransitionType(mTransitionType, mTransitionIndex);
           }
       });

3 编辑完转场效果后,设置合成参数

mKSYTransitionsKit.setEncodeMethod(mConfigParams.encodeMethod);
       mKSYTransitionsKit.setTargetSize(mConfigParams.width, mConfigParams.height);
       mKSYTransitionsKit.setVideoKBitrate(mConfigParams.videoBitrate);
       mKSYTransitionsKit.setAudioKBitrate(mConfigParams.audioBitrate);
       mKSYTransitionsKit.setAudioChannels(mConfigParams.audioChannel);
       mKSYTransitionsKit.setAudioSampleRate(mConfigParams.audioSampleRate);
       mKSYTransitionsKit.setVideoFps(mConfigParams.fps);
       mKSYTransitionsKit.setScaleMode(ImgTexScaleFilter.SCALING_MODE_BEST_FIT);
       mKSYTransitionsKit.setVideoDecodeMethod(mConfigParams.decodeMethod);

3 开始合成

       String outputFile = getFilesImportFolder() + "/outputFile" +
               System.currentTimeMillis() + ".mp4";
       mKSYTransitionsKit.startCompose(outputFile); 

4 接收到合成开始消息回调,显示合成进度dialog

      //建议暂停预览
      mKSYTransitionsKit.pausePreview();
      showProgressDialog();

5 Timer更新合成进度

mTimer = new Timer();
       mTimer.schedule(new TimerTask() {
           @Override
           public void run() {
               if (mKSYTransitionsKit != null && mComposeProgressDialog != null) {
                   KSYMultiEditKit.ComposeProgressInfo progressInfo = mKSYTransitionsKit
                           .getProgressInfo();
                   if (mComposeProgressDialog != null) {
                       mComposeProgressDialog.updateProgress((int) progressInfo.progress,
                               progressInfo.fileIdx);
                   }
               }
           }
       }, 500, 50);

6 接收到合成结束消息,关闭进度Dialog,进行下一步操作

                  if (mComposeProgressDialog != null) {
                       mComposeProgressDialog.dismiss();
                       mComposeProgressDialog = null;
                   }
                   MultiImportActivity.this.finish();
                   if (!TextUtils.isEmpty(msg)) {
                       EditActivity.startActivity(MultiImportActivity.this, msg);
                   }
Clone this wiki locally