Git Product home page Git Product logo

floatplayersample's Introduction

FloatPlayerSample

悬浮窗播放实现样例

主要功能

  • 悬浮窗播放视频
  • 点击悬浮窗进入全屏播放页面,并关闭悬浮窗
  • 点击悬浮窗右上角关闭悬浮窗

具体实现

为了保持悬浮窗和全屏播放页面视频播放同步,该样例使用一个Service来运行播放器,并在其Binder中提供方法来生成SurfaceView以显示视频内容
在PlayerService中,主要进行播放器的初始化和各种Listener的设置
Binder中,除了提供创建SurfaceView的方法外,还提供一些操作播放器的基础方法(设置监听器、设置资源文件、开始、暂停、结束等),以及跳转页面的方法(Service中跳转Activity需要加FLAG_ACTIVITY_NEW_TASK)

MainActivity中,首先绑定Service,在获得Binder后,通过Binder设置视频资源
FloatWindow初始化后,通过ApplicationContext绑定Service,在获取Binder后进行相关设置,并获取SurfaceView添加到悬浮窗预留的fl_container内
点击FloatWindow窗体,通过Binder调用PlayerService跳转Activity的方法,跳转到全屏播放页
进入全屏播放页后,首先应当绑定PlayerService,再关闭FloatWindow(关闭FloatWindow时FloatWindow创建时绑定的Service会解除绑定)

备注

  • 由于业务需要,视频播放器使用了阿里云播放器的SDK
  • 悬浮窗使用的是FloatWindow

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.