Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement Floating View for video streaming

I want to implement FloatingView. Which make Activity resize and draggable (like following Picture). I also see this thread and based on that I create my own service. (Also See this & this libraries)

The problem is According to implementation I can't continue Video and Also sometimes Screen goes to black and nothing displayed. I want to know what is the correct way to handle this? Without Video interrupted and continue playing. (I know interruption because of setOnPrepareListener but how avoid that?)

Here is my code:

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;
    }

} 

enter image description here

Edit: it's not draggable panel because in this app if user go to another activity video not interrupted and still playing.

like image 470
Amir Avatar asked Jul 27 '16 14:07

Amir


1 Answers

What you're trying to achieve is Picture in Picture, similar to what the YouTube app does.

Android officially supports this for TV, since Android N. For mobile devices however, you can use the Draggable Panel library.

like image 132
Suleiman19 Avatar answered Sep 30 '22 01:09

Suleiman19