2016-07-27 100 views
7

我想实现FloatingView。哪些使活动调整大小和可拖动(如下图)。我也看到这thread和基于我创建我自己的service。 (另请参阅this & this库)实现视频流的浮动视图

问题是根据实现我无法继续视频,而且有时屏幕会变黑并且不显示任何内容。我想知道处理这个问题的正确方法是什么?没有视频中断并继续播放。 (我知道是因为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; 
    } 

} 

enter image description here

编辑:这不是draggable panel因为在这个应用程序,如果用户转到其他活动视频不会中断并仍在播放。

+0

嗨,对于这个虚拟问题抱歉,但是当你说你“无法继续播放视频”时,究竟意味着什么?您是否无法“顺利”观看视频? – jos

+0

@jos正如你在Gif中看到的图像视频没有停止(或中断)。当调整大小活动不需要调用** setOnPreparedListener **时。 – Amir

回答

1

您试图实现的是Picture in Picture,类似于YouTube应用的功能。

Android正式支持这个电视,因为Android N。但对于移动设备,您可以使用Draggable Panel library

+0

感谢但可拖动面板不起作用,因为它绑定到它的活动,并且当你去到另一个活动draggable销毁。 – Amir

+0

这就是为什么我们使用Fragments,我的朋友:) – Suleiman19

+0

这是你认为它的片段的应用程序的链接? https://play.google.com/store/apps/details?id=tv.perception.android.aio – Amir