Giter Club home page Giter Club logo

piphone's Introduction

PiPhone

Version License Platform

PiPhone is a drop in solution to support picture-in-picture (user-initiated playback of video in a floating, resizable window) on iPhone devices. It's designed to mimic default AVPictureInPictureController behavior as much as possible.

Overview

Features

  • Picture in picture support for devices that doesn't support it by default
  • No additional work required if AVPictureInPictureController has been already configured
  • Same appearance as default one
  • Handling video size changing
  • Handling video errors
  • Supports tap, double tap, pinch and pan gestures
  • Mimic AVPictureInPictureControllerDelegate behavior

Requirements

  • Xcode 8.0+
  • iOS 9.0+

Installation

PiPhone is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'PiPhone'

Usage

To display video in picture-in-picture mode you can use both AVPlayerViewController and any custom video player configured to be diplayed in picture-in-picture.

Basically you don't need to perform any additional actions, your video players support picture-in-picture now! But PiPhone provides some customizations that you can find useful.

Make sure to import the framework header: #import <PiPhone/PiPhone.h> for Objective-C or import PiPhone for Swift.

Content inset adjustment behavior

Default AVPictureInPictureController behavior is to find the topmost UINavigationController's bar, UITabBarController's bar, safeAreaInsets, etc and determine where to place overlay video based on this metrics. Since imitation of this behavior turned out to be complicated and tricky process, it've been decided to control overlay video position based on predefined configurations.

PiPManagerContentInsetAdjustmentNavigationBar

Includes safe area insets and additional 44dp (32dp on landscape) inset from top safe area.

PiPManagerContentInsetAdjustmentTabBar

Includes safe area insets and additional 49dp (32dp on landscape in iOS 11 and above) inset from bottom safe area.

PiPManagerContentInsetAdjustmentNavigationAndTabBars

Includes both PiPManagerContentInsetAdjustmentNavigationBar and PiPManagerContentInsetAdjustmentTabBar.

PiPManagerContentInsetAdjustmentSafeArea

Includes safe area insets.

PiPManagerContentInsetAdjustmentNone

Overlay video is pinned to screen edges.

This behavior can be changed via PiPManager's contentInsetAdjustmentBehavior property.

Objective-C

PiPManager.contentInsetAdjustmentBehavior = PiPManagerContentInsetAdjustmentNavigationAndTabBars;

// animated
[UIView animateWithDuration:0.25 animations:^{
	PiPManager.contentInsetAdjustmentBehavior = PiPManagerContentInsetAdjustmentNavigationAndTabBars;
}];

Swift

PiPManager.contentInsetAdjustmentBehavior = .navigationAndTabBars

// animated
UIView.animate(withDuration: 0.25) {
	PiPManager.contentInsetAdjustmentBehavior = .navigationAndTabBars
}

Additional content insets

Also you can set extra spacing from screen edges to overlay video which will be added to automatically calculated one.

Objective-C

PiPManager.additionalContentInsets = UIEdgeInsetsMake(20, 10, 20, 10);

// animated
[UIView animateWithDuration:0.25 animations:^{
	PiPManager.additionalContentInsets = UIEdgeInsetsMake(20, 10, 20, 10);
}];

Swift

PiPManager.additionalContentInsets.top = 20

// animated
UIView.animate(withDuration: 0.25) {
	PiPManager.additionalContentInsets.top = 20
}

Disable picture-in-picture

You can temporarily disable picture-in-picture mode causing AVPictureInPictureController's isPictureInPicturePossible property to be false. Note: this will only have affect on iPhone.

Objective-C

// enable
PiPManager.pictureInPicturePossible = YES;

// disable
PiPManager.pictureInPicturePossible = NO;

Swift

// enable
PiPManager.isPictureInPicturePossible = true

// disable
PiPManager.isPictureInPicturePossible = false

To Do

  • Reduce private API usage
  • Investigate whether PiPPictureInPictureController should become a AVPictureInPictureController subclass
  • Implement rotation gesture, add 'soft' deceleration for pinch gesture
  • Improve automatic insets calculation

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Thanks & Credits

License

PiPhone is available under the MIT license. See the LICENSE file for more info.

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.