Skip to content

Instantly share code, notes, and snippets.

Payal Gupta pgpt10

  • Delhi
Block or report user

Report or block pgpt10

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Gradient2.swift
@IBDesignable class DesignableView: UIView
{
@IBInspectable var gradientColor1: UIColor = UIColor.white {
didSet{
self.setGradient()
}
}
@IBInspectable var gradientColor2: UIColor = UIColor.white {
didSet{
View CollectionViewGradient.swift
class CustomCollectionViewCell: UICollectionViewCell
{
//Gradient to add in the cell
private lazy var gradient: CAGradientLayer = {
let gradientLayer = CAGradientLayer()
gradientLayer.colors = [UIColor.darkGray.cgColor, UIColor.orange.cgColor]
gradientLayer.startPoint = CGPoint(x: 0, y: 0)
gradientLayer.endPoint = CGPoint(x: 1, y: 1)
gradientLayer.frame = self.bounds
return gradientLayer
View VideoStreaming6.swift
player.addPeriodicTimeObserver(forInterval: CMTime(seconds: 1, preferredTimescale: 2), queue: DispatchQueue.main) {[weak self] (progressTime) in
if let duration = player.currentItem?.duration {
let durationSeconds = CMTimeGetSeconds(duration)
let seconds = CMTimeGetSeconds(progressTime)
let progress = Float(seconds/durationSeconds)
DispatchQueue.main.async {
self?.progressBar.progress = progress
if progress >= 1.0 {
View DynamicHeightCollectionView.swift
class DynamicHeightCollectionView: UICollectionView {
override func layoutSubviews() {
super.layoutSubviews()
if!__CGSizeEqualToSize(bounds.size,self.intrinsicContentSize){
self.invalidateIntrinsicContentSize()
}
}
override var intrinsicContentSize: CGSize {
return contentSize
}
View VideoStreaming12.swift
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault, options: .mixWithOthers) //For playing volume when phone is on silent
} catch {
print(error.localizedDescription)
}
View VideoStreaming4.swift
public func playVideo() {
player?.play()
}
public func pauseVideo() {
player?.pause()
}
View VideoStreaming10.swift
func expandVideo() {
player?.pause()
let controller = AVPlayerViewController()
controller.player = player
NotificationCenter.default.addObserver(self, selector: #selector(avPlayerClosed), name: Notification.Name("avPlayerDidDismiss"), object: nil)
self.parentViewController()?.present(controller, animated: true) { in
DispatchQueue.main.async {
player?.play()
}
}
View VideoStreaming11.swift
extension AVPlayerViewController {
open override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.player?.pause()
NotificationCenter.default.post(name: Notification.Name("avPlayerDidDismiss"), object: nil, userInfo: nil)
}
}
View VideoStreaming9.swift
let controller = AVPlayerViewController()
controller.player = player //AVPlayer object
self.present(controller, animated: true) {[weak self] in
DispatchQueue.main.async {
player?.play()
}
}
View VideoStreaming8.swift
override public func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "timeControlStatus", let change = change, let newValue = change[NSKeyValueChangeKey.newKey] as? Int, let oldValue = change[NSKeyValueChangeKey.oldKey] as? Int {
let oldStatus = AVPlayer.TimeControlStatus(rawValue: oldValue)
let newStatus = AVPlayer.TimeControlStatus(rawValue: newValue)
if newStatus != oldStatus {
DispatchQueue.main.async {[weak self] in
if newStatus == .playing || newStatus == .paused {
self?.loaderView.isHidden = true
} else {
self?.loaderView.isHidden = false
You can’t perform that action at this time.