Android悬浮视频播放

本文介绍如何在Android设备上实现Picture-in-Picture (PiP)模式的视频播放功能。从Android O开始,应用程序可以使用PiP模式,在该模式下视频会继续播放,即使应用程序被最小化。文章详细解释了如何设置manifest文件以支持PiP模式,以及如何调整应用生命周期以确保视频播放不会在暂停时停止。
摘要由CSDN通过智能技术生成

android-PictureInPicture

项目地址:googlesamples/android-PictureInPicture 

标签:悬浮窗视频播放-

This sample demonstrates basic usage of Picture-in-Picture mode for handheld devices. The sample plays a video. The video keeps on playing when the app is turned in to Picture-in-Picture mode. On Picture-in-Picture screen, the app shows an action item to pause or resume the video.

Introduction

As of Android O, activities can launch in Picture-in-Picture (PiP) mode. PiP is a special type of multi-window mode mostly used for video playback.

The app is paused when it enters PiP mode, but it should continue showing content. For this reason, you should make sure your app does not pause playback in its onPause() handler. Instead, you should pause video in onStop(). For more information, see Multi-Window Lifecycle.

To specify that your activity can use PIP mode, set android:supportsPictureInPicture to true in the manifest. (Beginning with Android O, you do not need to set android:resizeableActivity to true if you are supporting PIP mode you only need to setrandroid:resizeableActivity if your activity supports other multi-window modes.)

You can pass a PictureInPictureParams to enterPictureInPictureMode() to specify how an activity should behave when it is in PiP mode. You can also use it to call setPictureInPictureParams() and update the current behavior. If the app is in not PiP mode, it will be used for later call of enterPictureInPictureMode().

With a PictureInPictureParams, you can specify aspect ratio of PiP activity and action items available for PiP mode. The aspect ratio is used when the activity is in PiP mode. The action items are used as menu items in PiP mode. You can use a PendingIntent to specify what to do when the item is selected.

Pre-requisites

  • Android SDK 27
  • Android Build Tools v27.0.2
  • Android Support Repository

Screenshots

Screenshot Screenshot

Getting Started

This sample uses the Gradle build system. To build this project, use the "gradlew build" command or use "Import Project" in Android Studio.

Support

If you've found an error in this sample, please file an issue: https://github.com/googlesamples/android-PictureInPicture

Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.

License

Copyright 2017 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值