Commit 26139159 authored by Soomin Lee's avatar Soomin Lee

MediaLibrary: RequestThumbnail when cell is loaded

parent d837330c
......@@ -28,7 +28,6 @@ class VideoModel: MediaModel {
self.medialibrary = medialibrary
medialibrary.addObserver(self)
files = medialibrary.media(ofType: .video)
medialibrary.requestThumbnail(for: files)
}
}
......
......@@ -359,12 +359,19 @@ extension MediaLibraryService {
// MARK: - Video methods
extension MediaLibraryService {
func requestThumbnail(for media: VLCMLMedia) {
if media.isThumbnailGenerated() || media.thumbnail() != nil {
return
}
if !media.requestThumbnail(of: .thumbnail, desiredWidth: 320, desiredHeight: 200, atPosition: 0.03) {
assertionFailure("MediaLibraryService: Failed to generate thumbnail for: \(media.identifier())")
}
}
func requestThumbnail(for media: [VLCMLMedia]) {
media.forEach() {
guard !$0.isThumbnailGenerated() else { return }
if !$0.requestThumbnail(of: .thumbnail, desiredWidth: 320, desiredHeight: 200, atPosition: 0.3) {
assertionFailure("MediaLibraryService: Failed to generate thumbnail for: \($0.identifier())")
}
requestThumbnail(for: $0)
}
}
}
......@@ -432,9 +439,6 @@ extension MediaLibraryService: VLCMediaLibraryDelegate {
let videos = media.filter {( $0.type() == .video )}
let tracks = media.filter {( $0.type() == .audio )}
// thumbnails only for videos
requestThumbnail(for: videos)
for observer in observers {
observer.value.observer?.medialibrary?(self, didAddVideos: videos)
observer.value.observer?.medialibrary?(self, didAddTracks: tracks)
......
......@@ -270,6 +270,8 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
}
let mediaObject = isSearching ? searchDataSource.objectAtIndex(index: indexPath.row) : model.anyfiles[indexPath.row]
if let media = mediaObject as? VLCMLMedia {
// FIXME: This should be done in the VModel, workaround for the release.
services.medialibraryService.requestThumbnail(for: media)
assert(media.mainFile() != nil, "The mainfile is nil")
mediaCell.media = media.mainFile() != nil ? media : nil
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment