簡單製作短視訊Demo
阿新 • • 發佈:2018-12-25
準備材料並配置專案工程:
1、去下載七牛雲播放器SDK
2、然後把pldroid-player-2.1.6.jar包拷貝到你專案lib檔案裡,詳情如下圖所示:
3、把整個jniLibs資料夾裡面的所有內容都拷貝到你專案src/main/裡,詳情如下圖所示:
4、然後在你專案build.gradle進行關聯
android {
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
}
dependencies {
implementation files('libs/pldroid-player-2.1.6.jar')
implementation 'com.bugsnag:bugsnag-android-ndk:1.1.2'
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.journeyapps:zxing-android-embedded: [email protected]'
implementation 'com.google.zxing:core:3.2.0'
}
5、然後在你專案xml佈局裡新增如下程式碼,PLVideoView控制元件:
<com.pili.pldroid.player.widget.PLVideoView android:id="@+id/VideoView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" />
6、最後去在你Activity裡找到這個控制元件並配置播放器程式碼:
mVideoView = findViewById(R.id.VideoView); AVOptions options = new AVOptions(); options.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, 10 * 1000); options.setInteger(AVOptions.KEY_MEDIACODEC, AVOptions.MEDIA_CODEC_SW_DECODE); options.setInteger(AVOptions.KEY_LIVE_STREAMING, 1 ); options.setInteger(AVOptions.KEY_LOG_LEVEL, 0); mVideoView.setAVOptions(options); // Set some listeners mVideoView.setOnInfoListener(mOnInfoListener); mVideoView.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener); mVideoView.setOnBufferingUpdateListener(mOnBufferingUpdateListener); mVideoView.setOnCompletionListener(mOnCompletionListener); mVideoView.setOnErrorListener(mOnErrorListener); mVideoView.setOnVideoFrameListener(mOnVideoFrameListener); mVideoView.setOnAudioFrameListener(mOnAudioFrameListener); mVideoView.setVideoPath(videoPath); mVideoView.setDisplayAspectRatio(mDisplayAspectRatio); mVideoView.setLooping(true); // You can also use a custom `MediaController` widget mMediaController = new MediaController(this, !mIsLiveStreaming, mIsLiveStreaming); mMediaController.setOnClickSpeedAdjustListener(mOnClickSpeedAdjustListener); mVideoView.setMediaController(mMediaController); 最後展示一下效果:
最後附上本人github,程式碼下載地址:https://github.com/Visen123/MyShortVideo ,如果覺得使用方便,請給我的github 點個贊,謝謝