This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
import Combine | |
// simply use | |
// player.periodicTimePublisher() | |
// .receive(on: RunLoop.main) | |
// .assign(to: \SomeClass.elapsedTime, on: someInstance) | |
// .store(in: &cancelBag) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func attributedString(for type: DateType, with date: Date) -> NSAttributedString { | |
let formatter = DateFormatter() | |
formatter.locale = Locale(identifier: "ar_EG") | |
formatter.dateFormat = "dd\nMMM\nyyyy" | |
if type == .hijri { | |
formatter.calendar = Calendar(identifier: .islamicCivil) | |
} | |
var formattedDate = formatter.string(from: date) | |
formattedDate += "\(type == . hijri ? "هـ" : "م")" | |
let attributedString = NSMutableAttributedString(string: formattedDate, attributes: [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
if [ "$CI" == true ]; then | |
echo "CI == true, skipping this script" | |
exit 0 | |
fi | |
SWIFT_LINT=./Pods/SwiftLint/swiftlint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class YourObjectVC: UIViewController { | |
var shareDelegate: ShareDelegate = ShareManager() | |
func onShareBtnPressed(_ sender: UIButton) { | |
shareDelegate.share("Hello, World!") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import AVFoundation | |
class Film { | |
//MARK: - Properties | |
var name: String | |
var path: URL | |
var duration: String { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Don't forget to import AVKit | |
func encodeVideo(at videoURL: URL, completionHandler: ((URL?, Error?) -> Void)?) { | |
let avAsset = AVURLAsset(url: videoURL, options: nil) | |
let startDate = Date() | |
//Create Export session | |
guard let exportSession = AVAssetExportSession(asset: avAsset, presetName: AVAssetExportPresetPassthrough) else { | |
completionHandler?(nil, nil) | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Don't forget to import AVFoundation | |
func getVideoDuration(from path: URL) -> String { | |
let asset = AVURLAsset(url: path) | |
let duration: CMTime = asset.duration | |
let totalSeconds = CMTimeGetSeconds(duration) | |
let hours = Int(totalSeconds / 3600) | |
let minutes = Int((totalSeconds.truncatingRemainder(dividingBy: 3600)) / 60) | |
let seconds = Int(totalSeconds.truncatingRemainder(dividingBy: 60)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Don't forget to import AVFoundation | |
func getVideoThumbnail(from path: URL?) -> UIImage? { | |
guard let path = path else { return nil } | |
do { | |
let asset = AVURLAsset(url: path , options: nil) | |
let imgGenerator = AVAssetImageGenerator(asset: asset) | |
imgGenerator.appliesPreferredTrackTransform = true | |
let cgImage = try imgGenerator.copyCGImage(at: CMTimeMake(0, 1), actualTime: nil) | |
let thumbnail = UIImage(cgImage: cgImage) |
NewerOlder