This is just a toy coder plugin for SDWebImage. Which aim to provide a demo usage that how SDWebImage combined the Animated Image View and Player and let it works for generic usage and customization.
Important: This project is just a toy, which means, it does not provide any production ready features, and the performances is really slow.
For real world rendering for short video files (like Imgur's GIFV format). You should always prefers to use the video player and rendering components, like AVKit's AVPlayerViewController .
This coder plugin, provide the animation loading support for video format, including:
- MP4 (MPEG/4)
- M4V (Apple iTunes Movie)
- MOV (QuickTime Movie)
- iOS 9+
- macOS 10.11+
- tvOS 9+
SDWebImageVideoCoder is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SDWebImageVideoCoder'
SDWebImageVideoCoder is available through Carthage.
github "SDWebImage/SDWebImageVideoCoder"
SDWebImageVideoCoder is available through Swift Package Manager.
let package = Package(
dependencies: [
.package(url: "https://github.com/SDWebImage/SDWebImageVideoCoder.git", from: "0.2.0")
]
)
For coder plugin usage, see Wiki - Coder Usage
- Objective-C
// register coder
[SDImageCodersManager.sharedCoder addCoder:SDImageVideoCoder.sharedCoder];
// load URL
SDAnimatedImageView *imageView;
NSURL *videoURL = [NSURL URLWithString:@"https://i.imgur.com/FY1AbSo.mp4"];
[imageView sd_setImageWithURL:videoURL];
- Swift
// register coder
SDImageCodersManager.shared.addCoder(SDImageVideoCoder.shared)
// load URL
let imageView: SDAnimatedImageView
let url = URL(string: "https://i.imgur.com/FY1AbSo.mp4")
imageView.sd_setImage(url: url)
For player usage, see Wiki - Animated Image Player
- Objective-C
// AVAsset
AVAsset *asset;
AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
generator.appliesPreferredTrackTransform = YES;
generator.requestedTimeToleranceBefore = kCMTimeZero;
generator.requestedTimeToleranceAfter = kCMTimeZero;
// player
SDAnimatedImagePlayer *player = [SDAnimatedImagePlayer playerWithProvider:generator];
player.animationFrameHandler = ^(NSUInteger index, UIImage * frame) {
// frames
};
[player seekToFrameAtIndex:5 loopCount:0];
[player play];
- Swift
let asset: AVAsset
let generator = AVAssetImageGenerator(asset: asset)
generator.appliesPreferredTrackTransform = true
generator.requestedTimeToleranceBefore = .zero
generator.requestedTimeToleranceAfter = .zero
// Player
let player = SDAnimatedImagePlayer(provider: generator)
player.animationFrameHandler = { (index, frame) in
// frames
}
player.seekToFrame(at: 5, loopCount: 0)
player.play()
To run the example project, clone the repo, and run pod install
from the Example directory first.
This demo MP4 video is from Imgur. You can always try you short video files as well.
DreamPiggy, lizhuoli1126@126.com
SDWebImageVideoCoder is available under the MIT license. See the LICENSE file for more info.