A video player SDK for iOS based on AVPlayer
FWPlayer
A video player SDK for iOS, it is based on AVPlayer.
Features
- [x] Supports horizontal and vertical playback
- [x] Supports auto-rotating screen playback
- [x] Supports the full-screen and mini-player playback
- [x] Supports mini-player position to drag freely
- [x] Supports the network and local video playback
- [x] Supports full-screen lock
- [x] Supports playback while downloading (Media Cache)
- [x] Supports vertical slide on the left side of the screen to adjust the brightness
- [x] Supports the vertical slide on the right side of the screen to adjust the volume
- [x] Supports gesture swipe fast-forward and rewind
- [x] Supports drag slider fast-forward and rewind
- [x] Supports direct jump to a point in the timeline to play
- [x] Supports multiple video formats
- [x] Supports UITableView playback
- [x] Supports UICollectionView playback
- [x] Supports UIScrollView playback
- [x] Supports background playback
- [x] Supports play sound in silent mode by default
- [x] Supports speed rate playback (0.5x, 1.0x, 1.25x, 1.5x, 2.0x)
- [x] Supports custom player view
- [x] Supports advertising view
- [x] Supports adding Http headers and other options to AVURLAsset
- FFmpeg is not supported because OpenGL ES was deprecated in iOS 12
Requirements
- iOS 9 +
- Xcode 10.2.1 +
Installation
You can install FWPlayer SDK in several ways:
CocoaPods
CocoaPods is an easy way to install FWPlayer.
- Add following pod to your
Podfile
:
platform :ios, '9.0'
target 'Your App' do
pod 'FWPlayer'
end
- Then, run the following command:
$ pod install
Carthage
Since FWPlayer SDK is distributed as a binary, you need to use custom binary
rule in your Cartfile
.
- Add following to your
Cartfile
:
binary "https://raw.githubusercontent.com/FoksWang/FWPlayer/master/Carthage/FWPlayer.json" >= 1.0.6
- Fetch framework by running:
$ carthage update FWPlayer --platform iOS
Manual Installation
- Add the FWPlayer framework to
Embedded Binaries
for your target:
FWPlayerCore.framework
- Make sure you link with the following
Linked Frameworks and Libraries
:
FWPlayerCore.framework
Usage
Normal Style
Objective-C
FWAVPlayerManager *playerManager = [[FWAVPlayerManager alloc] init];
self.player = [FWPlayerController playerWithPlayerManager:playerManager containerView:self.containerView];
self.player.controlView = self.controlView;
Swift
let playerManager = FWAVPlayerManager()
self.player = FWPlayerController(playerManager: playerManager, containerView: self.containerView)
self.player!.controlView = self.controlView
List Style
Objective-C
FWAVPlayerManager *playerManager = [[FWAVPlayerManager alloc] init];
self.player = [FWPlayerController playerWithScrollView:self.tableView playerManager:playerManager containerViewTag:tag];
self.player.controlView = self.controlView;
Swift
let playerManager = FWAVPlayerManager()
self.player = FWPlayerController(scrollView: tableView, playerManager: playerManager, containerViewTag: tag)
self.player!.controlView = self.controlView
- Your custom playerManager must conform to
FWPlayerMediaPlayback
protocol. - Your custom controlView must conform to
FWPlayerMediaControl
protocol.
Must implement in the ViewController if video rotating
Objective-C
- (BOOL)shouldAutorotate {
return player.shouldAutorotate;
}
Swift
override var shouldAutorotate: Bool {
return self.player?.shouldAutorotate ?? false
}
If use playback while downloading (Media Cache)
The function playback while downloading (Media Cache)
does NOT support m3u8, it is commonly used for MP4.
- Setup
isEnableMediaCache
Objective-C
playerManager.isEnableMediaCache = YES;
Swift
playerManager.isEnableMediaCache = true
- Setup
NSAppTransportSecurity
in yourInfo.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>