1.首先要下载sdk,我是以Module导入的(以Studio为例)
下载 Vitamio sdk的地址 https://www.vitamio.org/Download/
下载完成解压之后打开
打开之后看到的是
apply plugin: 'com.android.library'
dependencies {
}
android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
jniLibs.srcDirs = ['libs']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
} }}
根据自己建立的项目建立的版本选择在修改该之后是
apply plugin:'com.android.library'
dependencies {
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"//选择自己工程对应的sdk的版本
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs= ['src']
jniLibs.srcDirs= ['libs']
aidl.srcDirs= ['src']
renderscript.srcDirs= ['src']
res.srcDirs= ['res']
}}}
2.导入Module
File - New - import module
导入module之后就可以用了
布局很easy如图
导入完成之后就直接可以使用了
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.view.WindowManager;
import android.widget.Toast;
import java.util.Random;
import io.vov.vitamio.MediaPlayer;
import io.vov.vitamio.Vitamio;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
public class MainActivity extends Activity {
private VideoView mVideoViewPlay;
private String[]video = {
"http://dlqncdn.miaopai.com/stream/MVaux41A4lkuWloBbGUGaQ__.mp4",
"http://nebula-playback.qiniudn.com/test-playback/flv/sample.flv",//flv格式视频测试
"http://movie.ks.js.cn/flv/other/1_0.mp4",
"rtmp://live.hkstv.hk.lxdns.com/live/hks",//直播地址测试
"http://Media.zhbaby.org/BXLS/NewBaby/%E5%BC%80%E7%AF%87%E4%BB%8B%E7%BB%8D.mp4"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Vitamio.isInitialized(this);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置成全屏模式
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//强制为横屏
setContentView(R.layout.activity_main);
playfunction();
}
void playfunction() {
String path = "";
path = video[new Random().nextInt(video.length)];
if (path == "") {
Toast.makeText(this,"请填写视频的URL",Toast.LENGTH_LONG).show();
return;
}
mVideoViewPlay = (VideoView)findViewById(R.id.surface_view);
// mVideoViewPlay.setVideoPath("http://gslb.miaopai.com/stream/3D~8BM-7CZqjZscVBEYr5g__.mp4"); //设置视频网络地址
mVideoViewPlay.setVideoURI(Uri.parse(path));//也可以是本地,也可以是网络地址
mVideoViewPlay.setMediaController(new MediaController(this));//设置媒体控制器
mVideoViewPlay.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH,0);//设置视频的缩放参数,这里设置为拉伸
mVideoViewPlay.requestFocus();
//视频播放器的准备,此时播放器已经准备好了,此处可以设置一下播放速度,播放位置等等
mVideoViewPlay.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
//此处设置播放速度为正常速度1
mediaPlayer.setPlaybackSpeed(1.0f);
}
});
//当播放完成后,从头开始
mVideoViewPlay.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
mediaPlayer.seekTo(0);//转到第一帧
mediaPlayer.start();//开始播放
}
});
}
}
网友评论