但缺陷也是有的,多屏渲染目前而言,不依赖KtvSdk管理机制,那么意味着显示端需要自行管理Surface的生命周期。
KtvPlayerImpl player = new KtvPlayerImpl(); //创建播放器实例
//设置播放参数
KaraokePlayer.DataSourceType dataSourceType = KaraokePlayer.DataSourceType.ORIGINAL;
player.setTonePitchShift(0)
.setKtvVideoLayout(ktvVideoLayout) //传入KtvVideoMirrorLayout
.setDataSourceType(dataSourceType)
.setMicVolume(0.7F)
.setVolume(0.7F)
.addCallback(new KaraokePlayerListener() {
@Override
public void onVideoSizeChanged(KaraokePlayRequest request, int width, int height) {
super.onVideoSizeChanged(request, width, height);
if (callback != null) {
Message msg = Message.obtain();
msg.what = CALLBACK_ON_VIDEO_SIZE_CHANGED; //监听VideoSizeChanged
msg.arg1 = width;
msg.arg2 = height;
try {
callback.send(msg);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
});
player.play(songInfo);
val listener = object :MirrorSurfaceListener {
override fun onSurfaceCreated(surface: Surface?, width: Int, height: Int) {
ktvVideoLayout?.attachMirrorSurface(surface, width, height) //连接多屏渲染引擎
}
override fun onSurfaceChanged(surface: Surface?, width: Int, height: Int) {
ktvVideoLayout?.changeMirrorSurfaceSize(surface, width, height) // 调整视频画面缩放比
}
override fun onSurfaceDestroyed(surface: Surface?) {
ktvVideoLayout?.detachMirrorSurface(surface) //断开与渲染引擎的连接
}
};
/**
*
* @param width 视频宽度
* @param height 视频高度
* @param pixelWidthHeightRatio 视频宽高比 ,一般设置为 (width*1.0f)/height即可
*/
public void setVideoSize(int width, int height, float pixelWidthHeightRatio) {
}
public interface MirrorSurfaceConnectionListener {
void onSurfaceDestroyed(View parentView,IMirrorView childView,Surface surface);
void onSurfaceCreated(View parentView,IMirrorView childView,Surface surface, int width, int height);
void onSurfaceChanged(View parentView,IMirrorView childView,Surface surface, int width, int height);
}