All Projects → dingwilson → Swiftvideobackground

dingwilson / Swiftvideobackground

Licence: mit
📹 Framework to Play a Video in the Background of any UIView

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swiftvideobackground

sf-java-ui
Json Schema Form java based library allow developers to define schema and form using field annotations
Stars: ✭ 23 (-92.41%)
Mutual labels:  uiview
TinderUISamples
[ING] - TinderのようなUIを様々な実装で実現してみる
Stars: ✭ 30 (-90.1%)
Mutual labels:  uiview
UnityRawInput
Windows Raw Input wrapper for Unity game engine
Stars: ✭ 129 (-57.43%)
Mutual labels:  background
SwiftGradients
Useful extensions for UIViews and CALayer classes to add beautiful color gradients.
Stars: ✭ 15 (-95.05%)
Mutual labels:  uiview
bg-sound
Web Component to emulate the old-school <bgsound> HTML element
Stars: ✭ 93 (-69.31%)
Mutual labels:  background
UIView-SmoothCorners
An App-Store-safe way to enable smooth continuous corners on UIView that works on iOS 11, 12 and 13.
Stars: ✭ 91 (-69.97%)
Mutual labels:  uiview
Hola
Light-weight Onboard/Walkthrough UIView/UIImage representer ⏪ & ⏩ ⏫ & ⏬
Stars: ✭ 40 (-86.8%)
Mutual labels:  uiview
Uieffect
UIEffect is an effect component for uGUI element in Unity. Let's decorate your UI with effects!
Stars: ✭ 3,449 (+1038.28%)
Mutual labels:  background
celery.node
Celery task queue client/worker for nodejs
Stars: ✭ 164 (-45.87%)
Mutual labels:  background
ETBadge
A tool of swift to add or clear badge for any UIView。You can use it easily, also can custom it.
Stars: ✭ 19 (-93.73%)
Mutual labels:  uiview
cordova-plugin-apkupdater
This plugin allows your Android app to download and install compressed updates without the Google Play Store.
Stars: ✭ 46 (-84.82%)
Mutual labels:  background
react-native-dual
ScrollView, FlatList, SectionList and ListView with dual background
Stars: ✭ 28 (-90.76%)
Mutual labels:  background
geo-pattern
Create beautiful generative geometric background images from a string ✨ TypeScript port of jasonlong/geo_pattern. Supports both Node.js and Browser.
Stars: ✭ 33 (-89.11%)
Mutual labels:  background
ckLine
Generate random Background Lines it's great for Backgrounds
Stars: ✭ 20 (-93.4%)
Mutual labels:  background
UUAmountBoardView
[iOS]带有数字(金额)滚动效果的UI控件
Stars: ✭ 37 (-87.79%)
Mutual labels:  uiview
removd
Automatic ai cut outs of people, products and cars with https://www.remove.bg service
Stars: ✭ 28 (-90.76%)
Mutual labels:  background
ngx-animated-gradient
Angular Directive that animates the gradient background
Stars: ✭ 16 (-94.72%)
Mutual labels:  background
Onedrawable
✏️ Use only one image to set a background with a click effect for the View
Stars: ✭ 298 (-1.65%)
Mutual labels:  background
lovelace-animated-background
Animated backgrounds for lovelace
Stars: ✭ 123 (-59.41%)
Mutual labels:  background
BulkDownloader
BulkDownloader is used for multiple downloading process easy. It provides progress listener for each files and for whole file. It guarantees completion of download files as it runs on work manager
Stars: ✭ 24 (-92.08%)
Mutual labels:  background

Build Status codecov doccov Platform Swift MIT License CocoaPods Version Status Carthage compatible

SwiftVideoBackground is an easy to use Swift framework that provides the ability to play a video on any UIView. This provides a beautiful UI for login screens, or splash pages, as implemented by Spotify and many others.

Features

  • [x] Play a video with one line of code
  • [x] Supports local videos && videos from a web URL
  • [x] Automatically adjusts when device orientation changes
  • [x] Automatically resumes video when app re-enters foreground
  • [x] Pause, resume, restart, and other controls
  • [x] Loop videos (optional)
  • [x] Mute sound (optional)
  • [x] Darken videos so overlying UI stands out more (optional)
  • [x] Documentation

Contents

  1. Integration
  2. Migration Guide
  3. Usage
  4. License
  5. Authors

Integration

CocoaPods

You can use CocoaPods to install SwiftVideoBackground by adding it to your Podfile:

For Swift 5:

pod 'SwiftVideoBackground'

For Swift 4:

pod 'SwiftVideoBackground', '~> 3.0'

For Swift 3:

pod 'SwiftVideoBackground', '0.06'

Carthage

You can use Carthage to install SwiftVideoBackground by adding it to your Cartfile:

github "dingwilson/SwiftVideoBackground"

Manually

To use this library in your project manually you may:

  1. for Projects, just drag VideoBackground.swift to the project tree
  2. for Workspaces, include the whole SwiftVideoBackground.xcodeproj

Migration Guide

Version 3.0.0

Version 2.0.0

See the quick migration guide.

Usage

Example

import UIKit
import SwiftVideoBackground

class MyViewController: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()

    try? VideoBackground.shared.play(view: view, videoName: "myVideo", videoType: "mp4")

    /* or from URL */

    let url = URL(string: "https://coolVids.com/coolVid.mp4")!
    VideoBackground.shared.play(view: view, url: url)
  }
}

Documentation for Version 0.06 (Swift 3) can be found here.

Customization

play() has four additional optional parameters for customization:

  • darkness: CGFloat - Value between 0 and 1. The higher the value, the darker the video. Defaults to 0.
  • isMuted: Bool - Indicates whether video is muted. Defaults to true.
  • willLoopVideo: Bool - Indicates whether video should restart when finished. Defaults to true.
  • setAudioSessionAmbient: Bool - Indicates whether to set the shared AVAudioSession to ambient. If this is not done, audio played from your app will pause other audio playing on the device. Defaults to true.

So for example:

VideoBackground.shared.play(
    view: view,
    videoName: "myVideo",
    videoType: "mp4",
    darkness: 0.25,
    isMuted: false,
    willLoopVideo: true,
    setAudioSessionAmbient: true
)

-> will play the video with the sound on, slightly darkened, continuously looping, and without affecting other sources of audio on the device.

Any combination of the parameters can be included or left out.

setAudioSessionAmbient only has an effect in iOS 10.0+. For more information, see the docs.

Controls

  • pause() - Pauses the video.
  • resume() - Resumes the video.
  • restart() - Restarts the video.
  • getThumbnailImage(from: URL, at: CMTime) - Generate an image from the video to show as thumbnail.
  • darkness - Change this CGFloat to adjust the darkness of the video. Value 0 to 1. Higher numbers are darker. Setting to an invalid value does nothing.
  • isMuted - Change this Bool to mute/unmute the video.
  • willLoopVideo - Change this Bool to set whether the video restarts when it ends.
  • videoGravity - Default is .resizeAspectFill. Change to .resizeAspect (doesn't fill view) or .resize (doesn't conserve aspect ratio).
  • playerLayer - The AVPlayerLayer that can be accessed for advanced control and customization of the video.

Singleton

SwiftVideoBackground includes a singleton instance that can be conveniently accessed with VideoBackground.shared. An instance of VideoBackground can only play one video on one UIView at a time. So if you need to play on multiple UIViews, you need to retain an instance of VideoBackground for each UIView:

let videoBackground1 = VideoBackground()

Adding Videos To Your Project

In order to play local videos, you must add them to your project:

  1. Open project navigator
  2. Select your target
  3. Select Build Phases
  4. Select Copy Bundle Resources
  5. Click + to add a video

add video to project

License

SwiftVideoBackground is released under an MIT License. See LICENSE for details.

Authors

Wilson Ding, Quan Vo

Copyright © 2016-present Wilson Ding.

Please provide attribution, it is greatly appreciated.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].