# MD360Player4Android
It is a lite library to render 360 degree panorama video for Android.
[![](https://jitpack.io/v/ashqal/MD360Player4Android.svg)](https://jitpack.io/#ashqal/MD360Player4Android)
## Preview
![ScreenShot](https://github.com/ashqal/MD360Player4Android/raw/master/app/demo/preview.jpg)
![ScreenShot](https://github.com/ashqal/MD360Player4Android/raw/master/app/demo/preview1.jpg)
![ScreenShot](https://github.com/ashqal/MD360Player4Android/raw/master/app/demo/preview2.jpg)
## NOTICE
* OpenGLES 2.0 required
* Android 4.0.3 (Ice Cream Sandwich API-15) required
* Compatible with all Players which have `setSurface` api.
* This library do nothing but render the image of video frame, so you may deal with the issues about `MediaPlayer` or `IjkMediaPlayer` (e.g. play local file, rtmp, hls) by yourself;
* 这个库只负责视频帧画面的渲染,所有的视频文件播放、控制的工作都交给了`MediaPlayer`或者`IjkMediaPlayer`,你可能需要自己处理使用Player过程中出现的问题(比如播放本地文件、rtmp、hls).
## Last Commit
**`-SNAPSHOT`**
## Release Note
**2.0.1.beta**
* bug fix.
* add anti-distortion support.
```java
// init configuation
protected MDVRLibrary createVRLibrary() {
return MDVRLibrary.with(this)
...
.barrelDistortionConfig(new BarrelDistortionConfig().setDefaultEnabled(true).setScale(0.95f))
.build(R.id.gl_view);
}
```
```java
// setter
mVRLibrary.setAntiDistortionEnabled(true);
```
* hotspot support.
```java
// add hotspot dynamicly.
findViewById(R.id.button_add_plugin_logo).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
private MDPosition logoPosition = MDPosition.newInstance().setY(-8.0f).setYaw(-90.0f);
MDSimplePlugin plugin = MDSimplePlugin.builder()
.size(4f,4f)
.provider(new MDVRLibrary.IBitmapProvider() {
@Override
public void onProvideBitmap(MD360BitmapTexture.Callback callback) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.moredoo_logo);
callback.texture(bitmap);
}
})
.title("logo")
.position(logoPosition)
.listenClick(new MDVRLibrary.IPickListener() {
@Override
public void onHotspotHit(IMDHotspot hotspot, long hitTimestamp) {
Toast.makeText(MD360PlayerActivity.this, "click logo", Toast.LENGTH_SHORT).show();
}
})
.build();
plugins.add(plugin);
getVRLibrary().addPlugin(plugin);
Toast.makeText(MD360PlayerActivity.this, "add plugin logo" , Toast.LENGTH_SHORT).show();
}
});
```
* eye picker
```java
// setEyePickChangedListener dynamicly.
final TextView hotspotText = (TextView) findViewById(R.id.hotspot_text);
getVRLibrary().setEyePickChangedListener(new MDVRLibrary.IPickListener() {
@Override
public void onHotspotHit(IMDHotspot hotspot, long hitTimestamp) {
String text = hotspot == null ? "nop" : String.format(Locale.CHINESE, "%s %fs", hotspot.getTitle(), (System.currentTimeMillis() - hitTimestamp) / 1000.0f );
hotspotText.setText(text);
}
});
```
```java
// disable the eye picker
getVRLibrary().eyePickEanbled(false);
```
**1.5.3**
* Keep the GLContext instance onPause.
* GLTextureView supported!
**1.5.0**
* make the switch mode public. `switchInteractiveMode(Activity activity, int mode)` , `switchDisplayMode(Activity activity, int mode)` and `switchProjectionMode(Activity activity, int mode)`.
* add dome support.
* add stereo support.
* add plane support.
* switch projection in runtime support.
**1.4.0**
* better way to render multi screen. note:*Only one GLSurfaceView required now* !!
* `.build(R.id.surface_view1,R.id.surface_view2)` => `.build(R.id.surface_view)`
* add motion with touch strategy.
**1.3.0**
* add some reset function, such as `MDVRLibrary#resetPinch`,`MDVRLibrary#resetTouch`
* support sensor delay configuration in motion mode
* support sensorCallback
* fix a crucial bug: has an line in the center of the sphere
**1.2.0**
* pinch gesture supported
* changed the way to listen onClick event
* fix the image distortion on the polar of sphere
**1.1.0**
* Bitmap supported. For more info, See [BitmapPlayerActivity](https://github.com/ashqal/MD360Player4Android/tree/master/app/src/main/java/com/asha/md360player4android/BitmapPlayerActivity.java) in demo.
* Add callback if the TYPE_ROTATION_VECTOR is NOT supported.
* Use more divisions in sphere and load `.obj` file in working thread.
* Bug fix: Can not drag after setOnClickListener.
* Switch to [IjkMediaPlayer](https://github.com/Bilibili/ijkplayer) in demo.
**1.0.0**
* Motion Sensor
* Glass Mode(multi-screen)
* Fix a few bugs.
* More easier.
* Worked with MediaPlayer or ijkMediaPlayer.
## Gradle
```java
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
```
```java
dependencies {
compile 'com.github.ashqal:MD360Player4Android:1.5.3'
}
```
## USAGE
### Using with GLSurfaceView
**STEP1** Define `GLSurfaceView` in the layout xml.
```java
<android.opengl.GLSurfaceView
android:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
```
**STEP2** Init the `MDVRLibrary` in the Activity.
```java
public class MDVRLibraryDemoActivity extends MediaPlayerActivity {
private MDVRLibrary mVRLibrary;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_md_render);
// init VR Library
initVRLibrary();
}
private void initVRLibrary(){
// new instance
mVRLibrary = MDVRLibrary.with(this)
.displayMode(MDVRLibrary.DISPLAY_MODE_NORMAL)
.interactiveMode(MDVRLibrary.INTERACTIVE_MODE_MOTION)
.video(new MDVRLibrary.IOnSurfaceReadyCallback() {
@Override
public void onSurfaceReady(Surface surface) {
// IjkMediaPlayer or MediaPlayer
getPlayer().setSurface(surface);
}
})
.build(R.id.surface_view);
}
}
```
**STEP3** Addition call in `onTouchEvent` `onResume` `onPause` `onDestroy`.
```java
public class MDVRLibraryDemoActivity extends MediaPlayerActivity {
@Override
public boolean onTouchEvent(MotionEvent event) {
return mVRLibrary.handleTouchEvent(event) || super.onTouchEvent(event);
}
@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();
}
}
```
### Click Listener
`Builder#gesture`
```java
@Override
protected MDVRLibrary createVRLibrary() {
return MDVRLibrary.with(this)
.....
.gesture(new MDVRLibrary.IGestureListener() {
@Override
public void onClick(MotionEvent e) {
Toast.makeText(VideoPlayerActivity.this, "onClick!", Toast.LENGTH_SHORT).show();
}
})
.build(R.id.surface_view);
}
```
### Enable the pinch
`Builder#pinchEnabled`
```java
@Override
protected MDVRLibrary createVRLibrary() {
return MDVRLibrary.with(this)
.....
.pinchEnabled(true) //disable by default
.build(R.id.surface_view);
}
```
### Feature not support callback
add `ifNotSupport` to builder, e.g. [VideoPlayerActivity#createVRLibrary](https://github.c