我想实现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;
}
}
编辑:这不是draggable panel因为在这个应用程序,如果用户转到其他活动视频不会中断并仍在播放。
嗨,对于这个虚拟问题抱歉,但是当你说你“无法继续播放视频”时,究竟意味着什么?您是否无法“顺利”观看视频? – jos
@jos正如你在Gif中看到的图像视频没有停止(或中断)。当调整大小活动不需要调用** setOnPreparedListener **时。 – Amir