我想在不使用Unity的情况下构建虚拟现实视频播放器。有没有办法使用媒体播放器?
答案 0 :(得分:0)
你需要这个:
https://github.com/Rajawali/RajawaliVR
它适用于媒体播放器和本地文件,但如果您想要流式传输视频,则媒体播放器不是一个可靠的选择。
这是我的例子:
PlayerActivity
public class PlayerActivity extends RajawaliVRActivity {
private RajawaliVRExampleRenderer mRenderer;
private MediaPlayer mediaPlayer;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mRenderer = new RajawaliVRExampleRenderer(PlayerActivity.this);
setRenderer(mRenderer);
setConvertTapIntoTrigger(true);
}
/**
* Called when the Cardboard trigger is pulled.
*/
@Override
public void onCardboardTrigger() {
RajLog.i("onCardboardTrigger");
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
您需要一个渲染器类(我确定您可以修改MediaPlayer以满足您的需求)
public class RajawaliVRExampleRenderer extends RajawaliVRRenderer {
//"https://ia700401.us.archive.org/19/items/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4"
Context mContext;
private MediaPlayer mMediaPlayer;
private StreamingTexture mVideoTexture;
AppController appController;
boolean playing=false;
public RajawaliVRExampleRenderer(Context context) {
super(context);
mContext = context;
}
@Override
public void initScene() {
appController=(AppController)getContext().getApplicationContext();
//mMediaPlayer = MediaPlayer.create(getContext(),R.raw.video1);
mMediaPlayer=new MediaPlayer();
try {
mMediaPlayer.setAudioStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
mMediaPlayer.setDataSource("*URL*");
mMediaPlayer.prepareAsync();
} catch (IOException e) {
e.printStackTrace();
}
mMediaPlayer.setLooping(true);
mVideoTexture = new StreamingTexture("sintelTrailer", mMediaPlayer);
Material material = new Material();
material.setColorInfluence(0);
try {
material.addTexture(mVideoTexture);
} catch (ATexture.TextureException e) {
e.printStackTrace();
}
Sphere sphere = new Sphere(50, 64, 32);
sphere.setScaleX(-1);
sphere.setMaterial(material);
getCurrentScene().addChild(sphere);
getCurrentCamera().setPosition(Vector3.ZERO);
getCurrentCamera().setFieldOfView(75);
mMediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
Log.v("grebuf", "buffer (%):" + percent);
if (percent >= 20) {
if (!playing) {
//mMediaPlayer.start();
playing = true;
}
}
}
});
mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
Log.v("grega", "media start");
mp.start();
}
});
mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.d("grebuf",what+" "+extra);
return false;
}
});
}
@Override
public void onRender(long ellapsedRealtime, double deltaTime) {
super.onRender(ellapsedRealtime, deltaTime);
mVideoTexture.update();
}
@Override
public void onPause() {
super.onPause();
if (mMediaPlayer != null)
mMediaPlayer.pause();
}
@Override
public void onResume() {
super.onResume();
if (mMediaPlayer != null)
mMediaPlayer.start();
}
@Override
public void onRenderSurfaceDestroyed(SurfaceTexture surfaceTexture) {
super.onRenderSurfaceDestroyed(surfaceTexture);
mMediaPlayer.stop();
mMediaPlayer.release();
}
}
答案 1 :(得分:0)
对于基于Web的解决方案,您还可以查看React360(https://facebook.github.io/react-360/),它是Facebook的基于WebVR的框架,可以开箱即用地处理大多数3D媒体。 它在android上表现很好,并且具有渐进增强的优势,即,如果您从台式机/平板电脑查看它,您将获得2D体验,如果您使用支持3D的设备,则可以获得完整的VR体验。它也是跨平台的,因此可以在android / iOS / Windows / MacOS / Oculus / Vive上运行。 随附示例,足以让您入门。