9

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.

Community
  • 1
  • 1
Amir
  • 16,067
  • 10
  • 80
  • 119
  • Hi, sorry for this dummy question, but when you say that you "can't continue video" what it means exactly? Is that you can't watch the video "smoothly"? – jos Aug 09 '16 at 11:36
  • @jos As you see in Gif image video not stopped (or interrupted). when resize activity not need to call **setOnPreparedListener**. – Amir Aug 09 '16 at 14:10

1 Answers1

1

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.

Suleiman19
  • 742
  • 1
  • 7
  • 21
  • Thanks But Draggable panel not work because it's bind to it's activity and when you go to another activity draggable destroyed. – Amir Aug 08 '16 at 08:59
  • That is why we use Fragments, my friend :) – Suleiman19 Aug 08 '16 at 09:04
  • Here is a link of application you think it's fragment ? https://play.google.com/store/apps/details?id=tv.perception.android.aio – Amir Aug 08 '16 at 09:07
  • That would be hard to tell. But if I were you, I'd use Fragments to get it done. I'm sure the library's README has sufficiently explained how to set it up. – Suleiman19 Aug 08 '16 at 09:15
  • I decompile APK I'm sure it's a service ;) – Amir Aug 08 '16 at 09:16
  • If you look at the library, the Draggable component is simply a View. You could either let the player reside in that View, or use a Fragment. Depends upon your usage. – Suleiman19 Aug 09 '16 at 09:25
  • Yeah I see this library. But how go to another activity without call setOnPreparedListener? – Amir Aug 09 '16 at 14:11