1 |
efrain |
1 |

|
|
|
2 |
|
|
|
3 |
## Player
|
|
|
4 |
|
|
|
5 |
`Player` is a simple iOS video player library written in [Swift](https://developer.apple.com/swift/).
|
|
|
6 |
|
|
|
7 |
[](https://travis-ci.com/piemonte/Player) [](http://cocoadocs.org/docsets/Player/) [](https://developer.apple.com/swift) [](https://github.com/piemonte/Player/blob/master/LICENSE)
|
|
|
8 |
|
|
|
9 |
- Looking for an obj-c video player? Check out [PBJVideoPlayer (obj-c)](https://github.com/piemonte/PBJVideoPlayer).
|
|
|
10 |
- Looking for a Swift camera library? Check out [Next Level](https://github.com/NextLevel/NextLevel).
|
|
|
11 |
|
|
|
12 |
Need a different version of Swift?
|
|
|
13 |
* `5.0` - Target your Podfile to the latest release or master
|
|
|
14 |
* `4.2` - Target your Podfile to the `swift4.2` branch
|
|
|
15 |
* `4.0` - Target your Podfile to the `swift4.0` branch
|
|
|
16 |
|
|
|
17 |
### Features
|
|
|
18 |
|
|
|
19 |
- [x] plays local media or streams remote media over HTTP
|
|
|
20 |
- [x] customizable UI and user interaction
|
|
|
21 |
- [x] no size restrictions
|
|
|
22 |
- [x] orientation change support
|
|
|
23 |
- [x] simple API
|
|
|
24 |
- [x] video frame snapshot support
|
|
|
25 |
|
|
|
26 |
# Quick Start
|
|
|
27 |
|
|
|
28 |
`Player` is available for installation using the Cocoa dependency manager [CocoaPods](http://cocoapods.org/). Alternatively, you can simply copy the `Player.swift` file into your Xcode project.
|
|
|
29 |
|
|
|
30 |
```ruby
|
|
|
31 |
# CocoaPods
|
|
|
32 |
pod "Player", "~> 0.13.2"
|
|
|
33 |
|
|
|
34 |
# Carthage
|
|
|
35 |
github "piemonte/Player" ~> 0.13.2
|
|
|
36 |
```
|
|
|
37 |
|
|
|
38 |
## Usage
|
|
|
39 |
|
|
|
40 |
The sample project provides an example of how to integrate `Player`, otherwise you can follow these steps.
|
|
|
41 |
|
|
|
42 |
Allocate and add the `Player` controller to your view hierarchy.
|
|
|
43 |
|
|
|
44 |
``` Swift
|
|
|
45 |
self.player = Player()
|
|
|
46 |
self.player.playerDelegate = self
|
|
|
47 |
self.player.playbackDelegate = self
|
|
|
48 |
self.player.view.frame = self.view.bounds
|
|
|
49 |
|
|
|
50 |
self.addChild(self.player)
|
|
|
51 |
self.view.addSubview(self.player.view)
|
|
|
52 |
self.player.didMove(toParent: self)
|
|
|
53 |
```
|
|
|
54 |
|
|
|
55 |
Provide the file path to the resource you would like to play locally or stream. Ensure you're including the file extension.
|
|
|
56 |
|
|
|
57 |
``` Swift
|
|
|
58 |
let videoUrl: URL = // file or http url
|
|
|
59 |
self.player.url = videoUrl
|
|
|
60 |
```
|
|
|
61 |
|
|
|
62 |
play/pause
|
|
|
63 |
|
|
|
64 |
``` Swift
|
|
|
65 |
self.player.playFromBeginning()
|
|
|
66 |
```
|
|
|
67 |
|
|
|
68 |
Adjust the fill mode for the video, if needed.
|
|
|
69 |
|
|
|
70 |
``` Swift
|
|
|
71 |
self.player.fillMode = .resizeAspectFit
|
|
|
72 |
```
|
|
|
73 |
|
|
|
74 |
Display video playback progress, if needed.
|
|
|
75 |
|
|
|
76 |
``` Swift
|
|
|
77 |
extension ViewController: PlayerPlaybackDelegate {
|
|
|
78 |
|
|
|
79 |
public func playerPlaybackWillStartFromBeginning(_ player: Player) {
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
public func playerPlaybackDidEnd(_ player: Player) {
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
public func playerCurrentTimeDidChange(_ player: Player) {
|
|
|
86 |
let fraction = Double(player.currentTime) / Double(player.maximumDuration)
|
|
|
87 |
self._playbackViewController?.setProgress(progress: CGFloat(fraction), animated: true)
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
public func playerPlaybackWillLoop(_ player: Player) {
|
|
|
91 |
self. _playbackViewController?.reset()
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
}
|
|
|
95 |
```
|
|
|
96 |
|
|
|
97 |
## Documentation
|
|
|
98 |
|
|
|
99 |
You can find [the docs here](http://piemonte.github.io/Player/). Documentation is generated with [jazzy](https://github.com/realm/jazzy) and hosted on [GitHub-Pages](https://pages.github.com).
|
|
|
100 |
|
|
|
101 |
## Community
|
|
|
102 |
|
|
|
103 |
- Need help? Use [Stack Overflow](http://stackoverflow.com/questions/tagged/player-swift) with the tag 'player-swift'.
|
|
|
104 |
- Questions? Use [Stack Overflow](http://stackoverflow.com/questions/tagged/player-swift) with the tag 'player-swift'.
|
|
|
105 |
- Found a bug? Open an [issue](https://github.com/piemonte/player/issues).
|
|
|
106 |
- Feature idea? Open an [issue](https://github.com/piemonte/player/issues).
|
|
|
107 |
- Want to contribute? Submit a [pull request](https://github.com/piemonte/player/pulls).
|
|
|
108 |
|
|
|
109 |
## Resources
|
|
|
110 |
|
|
|
111 |
* [Swift Evolution](https://github.com/apple/swift-evolution)
|
|
|
112 |
* [AV Foundation Programming Guide](https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html)
|
|
|
113 |
* [Next Level](https://github.com/NextLevel/NextLevel/), rad media capture in Swift
|
|
|
114 |
* [PBJVision](https://github.com/piemonte/PBJVision), iOS camera engine, features touch-to-record video, slow motion video, and photo capture
|
|
|
115 |
* [PBJVideoPlayer](https://github.com/piemonte/PBJVideoPlayer), a simple iOS video player library, written in obj-c
|
|
|
116 |
|
|
|
117 |
## License
|
|
|
118 |
|
|
|
119 |
Player is available under the MIT license, see the [LICENSE](https://github.com/piemonte/player/blob/master/LICENSE) file for more information.
|