andreipitis / ASPVideoPlayer

A simple video player that allow animations to be performed on the view during playback.
MIT License
89 stars 43 forks source link
ios swift uiview video-player

ASPVideoPlayer

CI Status codebeat badge codecov Version License Platform

Example

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

Usage

There are two objects you can use to display a video:

  1. ASPVideoPlayer
  2. ASPVideoPlayerView

1. ASPVideoPlayer

aspvideoplayer

ASPVideoPlayer is a full video player with UI controls.

You should use this if you just want to display videos in a player with controls such as play, pause, scrub, next, previous.

let videoPlayer = ASPVideoPlayer()
@IBOutlet weak var videoPlayer: ASPVideoPlayer!
let firstVideoURL = Bundle.main.url(forResource: "video", withExtension: "mp4")
let secondVideoURL = Bundle.main.url(forResource: "video2", withExtension: "mp4")

videoPlayer.videoURLs = [firstVideoURL!, secondVideoURL!]

videoPlayer.gravity = .aspectFit

videoPlayer.shouldLoop = true

2. ASPVideoPlayerView

ASPVideoPlayerView is a component that ASPVideoPlayer uses to display the video, but you can also use it by itself.

It's a simple UIView with no UI elements.

If you wish to implement your own video player, or want a simple component to display a single video with no other UI elements, you should use this.

let videoPlayer = ASPVideoPlayerView()
@IBOutlet weak var videoPlayer: ASPVideoPlayerView!
let videoURL = Bundle.main.url(forResource: "video", withExtension: "mp4")

videoPlayer.videoURL = videoURL

videoPlayer.readyToPlayVideo = {
  print("Video has been successfully loaded and can be played.")
}

videoPlayer.startedVideo = {
  print("Video has started playing.")           
}

Installation

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

pod "ASPVideoPlayer"

Author

Andrei-Sergiu Pitis, andy.pitis@gmail.com

License

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