Presentation 双屏异显

DisplayManager

    private void showOtherDisPlay() {
        DisplayManager displayManager = (DisplayManager) this.getSystemService(Context.DISPLAY_SERVICE);
        presentationDisplays = displayManager.getDisplays();
        if (presentationDisplays.length > 1) {
            presentation = new DifferentDisplay(getApplicationContext(), presentationDisplays[1]);
            presentation.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
            presentation.show();
            videoView = presentation.videoView;
            rn_layout = presentation.localView;
            JCManager.getInstance().mediaDevice.specifyCamera(1, 640, 320);
            JCMediaDeviceVideoCanvas mLocalCanvas = JCManager.getInstance().mediaDevice.startCameraVideo(JCMediaDevice.RENDER_FULL_CONTENT);
            mLocalCanvas.getVideoView().setZOrderMediaOverlay(true);
            mLocalCanvas.getVideoView().setId(View.generateViewId());
            rn_layout.addView(mLocalCanvas.getVideoView(), 0);
        } else {
            //  presentation = new DifferentDisplay( this, presentationDisplays[0]);
        }
    }

获取屏幕的方式还用另一种

Presentation

public class DifferentDisplay extends Presentation {
    public VideoView videoView;
    public RelativeLayout localView;

    public DifferentDisplay(Context outerContext, Display display) {
        super(outerContext, display);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.play_video);

        videoView = (VideoView ) findViewById(R.id.video_view);
        localView = findViewById(R.id.loacol_view);
    }

}

此为dialog,需要注意的是此dialog的生命周期是跟随activity的,当activity不再主显示那么此Presentation 就会销毁。

最终采用的方案是将dialog级别设置为悬浮窗口:

presentation = new DifferentDisplay(getApplicationContext(), presentationDisplays[1]);
            presentation.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

你可能感兴趣的:(Android,应用层开发)