android開發之音視頻(一)

轉載請標明出處:
http://blog.csdn.net/AnalyzeSystem/article/details/78489729
本文出自Analyzesystem的博客

做android端音視頻項目開發有幾個月了,來做個小結


開發框架選取

android手機有很多自帶播放器不支持流媒體播放、音頻格式等因素,爲此開發需要採用成熟開源框架或自己修改FFmpeg,長爲人熟知的開源框架有一下幾款:

  • vitamio
  • SmarterStreaming
  • GSYVideoPlayer
  • PLDroidPlayer
  • ijkplayer
    …………………….

    vitamio 要收費,七牛PLDroidPlayer 修改底層源碼不方便(由於項目是視頻監控行業,很多定製需求,要求能高度定製底層源碼),最後採取bilibili開源的ijkplayer,GSYVideoPlayer雖然封裝的很好,但是不適合手裏項目。

關於ijkplayer so庫編譯,最好別再window下進行,容易出現符號佔位符等問題。編譯好後分別在 對應目錄生成三個so庫和一個.aar文件,依賴如果出現.aar 相關的類找不到(aar沒有更新),而自己又確定有的情況下,可參考tip


gradle.properties

/***true:啓用 build cache,反之禁用。如果這個參數未設置,默認是禁用 build cache.***/

android.enableBuildCache= 

當你遇到視頻播放出來了但沒聲音,多數是音頻格式支持問題,默認腳本沒有添加太多的格式支持,需要自己修改,具體操作可參考issues

ijkplayer demo提供的僅TextureView渲染的才能截圖,產品要求視頻仿螢石雲,能手勢縮放拖拽、截圖、、錄像、語音對講等功能,沒辦法視頻播放器控件只能自己想辦法,所幸找到了一個開源庫ScaleVideoView

https://github.com/yushiwo/ScaleVideoView

視頻相關功能博主這兒有專業人員修改ijkplayer源碼,在IMediaPlayer爲博主提供可調用函數以及相關接口監聽器,修改ScaleVideoView源碼以及so庫依賴,添加相應函數調用即可。

Tip: 未播放過的視頻也可以通過修改ijkplayer底層實現獲取第一幀圖(用於設置封面CoverView)

關於視頻相關的控制統一稱爲控制器,控制器相關自動隱藏顯示動畫相關代碼塊如下

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;

/**
 * Created by idea on 2017/10/23.
 */

public class TranslateAnimationHelper {

    private static void translateX(View view, int translateStartX,int translateEndX){
        Animation animation = new TranslateAnimation(translateStartX*view.getMeasuredWidth(), translateEndX*view.getMeasuredWidth(), 0, 0);
        animation.setDuration(500);
        animation.setRepeatCount(0);//動畫的重複次數
        animation.setFillAfter(true);//設置爲true,動畫轉化結束後被應用
        view.startAnimation(animation);//開始動畫
    }

    private static void translateY(View view,int translateStartY,int translateEndY){
        Animation animation = new TranslateAnimation(0, 0,translateStartY*view.getMeasuredHeight(),translateEndY*view.getMeasuredHeight());
        animation.setDuration(500);
        animation.setRepeatCount(0);//動畫的重複次數
        animation.setFillAfter(true);//設置爲true,動畫轉化結束後被應用
        view.startAnimation(animation);//開始動畫
    }

    public static void hideTopView(View view){
        TranslateAnimationHelper.translateY(view,0,-1);
    }

    public static void showTopView(View view){
        TranslateAnimationHelper.translateY(view,-1,0);
    }

    public static void hideBottomView(View view){
        TranslateAnimationHelper.translateY(view,0,1);
    }

    public static void showBottomView(View view){
        TranslateAnimationHelper.translateY(view,1,0);
    }

    public static void hideLeftView(View view){
        TranslateAnimationHelper.translateX(view,0,-1);
    }

    public static void showLeftView(View view){
        TranslateAnimationHelper.translateX(view,-1,0);
    }

    public static void hideRightView(View view){
        TranslateAnimationHelper.translateX(view,0,1);
    }

    public static void showRightView(View view){
        TranslateAnimationHelper.translateX(view,1,0);
    }

    public static void toggleVisibility(View left,View top,View right,View bottom,boolean isHide){
        if(isHide){
            hideView(left,top,right,bottom);
        }else{
            showView(left,top,right,bottom);
        }
    }

    private static void showView(View left, View top, View right, View bottom) {
        if(left!=null){
            hideLeftView(left);
        }

        if(top!=null){
            hideTopView(top);
        }

        if(right!=null){
            hideRightView(right);
        }

        if(bottom!=null){
            hideBottomView(bottom);
        }
    }

    private static void hideView(View left, View top, View right, View bottom) {
        if(left!=null){
            showLeftView(left);
        }

        if(top!=null){
            showTopView(top);
        }

        if(right!=null){
            showRightView(right);
        }

        if(bottom!=null){
            showBottomView(bottom);
        }
    }


}

錄像回放關聯的時間軸控件,採用開源控件TimeRule,不過源碼需要二次修改


// https://github.com/dingyongxiang/TimeRulers

最終實現效果圖



本篇僅爲概述,如有雷同請忽略,下一篇博客進入主題..

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章