最近做 android 项目 需要 全景播放器和相关的 播放器参数 所以遇到的一些 小知识 记录一下
在开始用他之前也找了好多 播放器,pano360 Uotvr 。。。最中还是用了 这个
项目 Git :https://github.com/ashqal/MD360Player4Android
应用方法:https://jitpack.io/#ashqal/MD360Player4Android
以下是最官网的步骤,没有问题,
Using with GLSurfaceView
STEP1 Define GLSurfaceView in the layout xml.
STEP2 Init the MDVRLibrary in the Activity.
publicclassMDVRLibraryDemoActivityextendsActivity{privateMDVRLibrarymVRLibrary;@OverridepublicvoidonCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState); setContentView(R.layout.activity_md_render);//init VR LibraryinitVRLibrary(); }privatevoidinitVRLibrary(){//new instancemVRLibrary=MDVRLibrary.with(this) .displayMode(MDVRLibrary.DISPLAY_MODE_NORMAL) .interactiveMode(MDVRLibrary.INTERACTIVE_MODE_MOTION) .asVideo(newMDVRLibrary.IOnSurfaceReadyCallback() {@OverridepublicvoidonSurfaceReady(Surfacesurface) {//IjkMediaPlayer or MediaPlayergetPlayer().setSurface(surface); } }) .build(R.id.surface_view); }}
STEP3 Addition call in onResume onPause onDestroy onConfigurationChanged.
publicclassMDVRLibraryDemoActivityextendsMediaPlayerActivity{@OverrideprotectedvoidonResume() {super.onResume(); mVRLibrary.onResume(this); }@OverrideprotectedvoidonPause() {super.onPause(); mVRLibrary.onPause(this); }@OverrideprotectedvoidonDestroy() {super.onDestroy(); mVRLibrary.onDestroy(); }@OverridepublicvoidonConfigurationChanged(ConfigurationnewConfig) {super.onConfigurationChanged(newConfig); mVRLibrary.onOrientationChanged(this); }}
一下是我个人的代码
1 Step Layout
2 Step
package com.app.yispace.app.myapplication;
import android.content.Context;
import android.content.res.Configuration;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnMediaTimeDiscontinuityListener;
import android.media.MediaTimestamp;
import android.opengl.EGLDisplay;
import android.opengl.GLSurfaceView;
import android.os.Handler;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Surface;
import com.asha.vrlib.MD360Director;
import com.asha.vrlib.MD360DirectorFactory;
import com.asha.vrlib.MDVRLibrary;
import com.asha.vrlib.model.BarrelDistortionConfig;
import com.asha.vrlib.model.MDFlingConfig;
import com.asha.vrlib.model.MDPosition;
import com.asha.vrlib.model.MDQuaternion;
import com.asha.vrlib.objects.MDAbsObject3D;
import com.asha.vrlib.strategy.projection.AbsProjectionStrategy;
import com.asha.vrlib.strategy.projection.IMDProjectionFactory;
//import com.player.panoplayer.OptionType;
//import com.player.panoplayer.OptionValue;
//import com.player.panoplayer.PanoPlayer;
//import com.player.panoplayer.PanoPlayerUrl;
//import com.player.renderer.PanoPlayerSurfaceView;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.microedition.khronos.egl.EGL10;
public class MainActivityextends AppCompatActivity {
private MDVRLibrarymVRLibrary;
Handlerhandler =new Handler();
private GLSurfaceViewsurfaceView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
surfaceView = findViewById(R.id.surface_view);
initVRLibrary();
}
private void initVRLibrary() {
// 这个是 圆筒形开关开,我们球面投影不需要设置
BarrelDistortionConfig barrelDistortionConfig =new BarrelDistortionConfig();
barrelDistortionConfig.setDefaultEnabled(false);
// 这里的 setParamA B C 应该是透镜的三次 边缘即便参数
// // barrelDistortionConfig.setParamA();
mVRLibrary = MDVRLibrary.with(this)
.displayMode(MDVRLibrary.DISPLAY_MODE_NORMAL)//这里是 单双屏幕设置
.interactiveMode(MDVRLibrary.INTERACTIVE_MODE_MOTION_WITH_TOUCH)//设置你的活动方式
// 触碰和陀螺仪 但是用 陀螺仪时 必须用 下面 mVRLibrary.onOrientationChanged(this);
.motionDelay(100)//陀螺仪的延迟
.projectionMode(MDVRLibrary.PROJECTION_MODE_SPHERE)//这里是 设置投影模式,都是 DISPLAY_MODE_***
.directorFilter(new MDVRLibrary.IDirectorFilter() {// 这个是用作设置渲染时候 位置的控制及限定
@Override
public float onFilterPitch(float v) {//维度的限定
if (v >=85)
return 85;
else if (v <= -85)
return -85;
else
return v;
}
@Override
public float onFilterYaw(float v) {// 精度的限定
return v;
}
@Override
public float onFilterRoll(float v) {//这里是 Z轴 的限定
if (v <=45 && v >= -45)
return 0;
else if (v >45 && v <=135)
return 90;
else if (v >= -153 && v < -45)
return -90;
else {
return 180;
}
}
})
.pinchEnabled(false)//放缩的支持
.flingEnabled(true)//甩动的支持,但是感觉没有什么效果,他话有个,他话有个 flingCongfig 进行进一步配置
.barrelDistortionConfig(barrelDistortionConfig)//上面说了
.asVideo(new MDVRLibrary.IOnSurfaceReadyCallback() {// as** 是处理的文件展示类型
@Override
public void onSurfaceReady(Surface surface) {
getPlayer().setSurface(surface);
}
})
.build(surfaceView);//这个是设置 surface Android 的工程师应该都知道他
mVRLibrary.onOrientationChanged(this);
// 同时这还有一些小的设置可以动过 mVRLibrary 来设置 又提示
}
// 这里是加载 视频源的
MediaPlayer getPlayer() {
MediaPlayer mediaPlayer =new MediaPlayer();
try {
mediaPlayer.setDataSource("http://192.168.1.171:8071/UploadFiles/960p/1080.mp4");
mediaPlayer.prepare();
mediaPlayer.start();
handler.postDelayed(runnable,40);
}catch (IOException e) {
e.printStackTrace();
}
return mediaPlayer;
}
Runnablerunnable =new Runnable() {
@Override
public void run() {
Log.d("ssss","getPitch" +mVRLibrary.getDirectorBrief().getPitch() +" getYaw" +mVRLibrary
.getDirectorBrief().getYaw() +" getRoll" +mVRLibrary.getDirectorBrief().getRoll());
handler.postDelayed(this,1000);
}
};
@Override
protected void onResume() {
super.onResume();
mVRLibrary.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
mVRLibrary.onPause(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
mVRLibrary.onDestroy();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mVRLibrary.onOrientationChanged(this);
}
}
这里也都给大家说了他的配置和过去方法,看一下LOG j就明白了都是什么了 哈哈哈
OK 感觉这个作者很多好久 NB 考虑的很全面,可能还是有一些 不足,但是有一个能写出来那?哈哈哈