为视频流实施浮动视图

Ami*_*mir 9 android video-streaming android-videoview

我想实施FloatingView.这使活动调整大小和拖动(如下图).我也看到了这个帖子,并在此基础上创建了自己的帖子service.(另请参见&这个库)

问题是根据实现我不能继续视频,有时屏幕变黑,没有任何显示.我想知道处理这个问题的正确方法是什么?没有视频中断并继续播放.(我知道中断因为setOnPrepareListener但是如何避免?)

这是我的代码:

public class FloatingStream extends Service implements FloatingViewListener {


    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (mFloatingViewManager != null) {
            return START_STICKY;
        }


        final DisplayMetrics metrics = new DisplayMetrics();
        final WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        windowManager.getDefaultDisplay().getMetrics(metrics);
        floatingServiceBinder = new FloatingServiceBinder(this);
        final View rootView = LayoutInflater.from(this).inflate(R.layout.view_exoplayer, null, false);
        final VideoView videoView = (VideoView) rootView.findViewById(R.id.video_view);
        videoView.setVideoURI(Uri.parse(MY_URL));
        videoView.setOnPreparedListener(new OnPreparedListener() {
            @Override
            public void onPrepared() {
                videoView.start();
            }
        });

        mFloatingViewManager = new FloatingViewManager(this, this);
        mFloatingViewManager.setFixedTrashIconImage(R.drawable.ic_play_circle_filled);
        mFloatingViewManager.setActionTrashIconImage(R.drawable.ic_menu);
        final FloatingViewManager.Options options = new FloatingViewManager.Options();
        mFloatingViewManager.addViewToWindow(rootView, options);


        return START_REDELIVER_INTENT;
    }

} 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

编辑:它不是可拖动的面板,因为在这个应用程序中,如果用户转到另一个活动视频而不是中断并仍在播放.

Sul*_*n19 1

您想要实现的是画中画,类似于 YouTube 应用程序的功能。

自 Android N 起,Android 正式支持电视这一功能。但是,对于移动设备,您可以使用Draggable Panel 库