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 notify | |
import Combine | |
enum Notify {} | |
extension Notify { | |
struct Status: Error { | |
let rawValue: UInt32 | |
init(_ rawValue: UInt32) { | |
self.rawValue = rawValue |
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 AVKit | |
import AVFoundation | |
extension Data { | |
func toCMBlockBuffer() throws -> CMBlockBuffer { | |
var blockBuffer: CMBlockBuffer? | |
let data: NSMutableData = .init(data: self) | |
var source: CMBlockBufferCustomBlockSource = .init() | |
source.refCon = Unmanaged.passRetained(data).toOpaque() |
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
scalacOptions ++= Seq( | |
"-deprecation", // Emit warning and location for usages of deprecated APIs. | |
"-encoding", "utf-8", // Specify character encoding used by source files. | |
"-explaintypes", // Explain type errors in more detail. | |
"-feature", // Emit warning and location for usages of features that should be imported explicitly. | |
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred | |
// "-language:experimental.macros", // Allow macro definition (besides implementation and application). Disabled, as this will significantly change in Scala 3 | |
"-language:higherKinds", // Allow higher-kinded types | |
// "-language:implicitConversions", // Allow definition of implicit functions called views. Disabled, as it might be dropped in Scala 3. Instead use extension methods (implemented as implicit class Wrapper(va |
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
extension CVPixelBuffer { | |
public static func from(_ data: Data, width: Int, height: Int, pixelFormat: OSType) -> CVPixelBuffer { | |
data.withUnsafeBytes { buffer in | |
var pixelBuffer: CVPixelBuffer! | |
let result = CVPixelBufferCreate(kCFAllocatorDefault, width, height, pixelFormat, nil, &pixelBuffer) | |
guard result == kCVReturnSuccess else { fatalError() } | |
CVPixelBufferLockBaseAddress(pixelBuffer, []) | |
defer { CVPixelBufferUnlockBaseAddress(pixelBuffer, []) } |
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 asynchronouslyLoadURLAssets(_ newAsset: AVURLAsset) { | |
DispatchQueue.main.async { | |
newAsset.loadValuesAsynchronously(forKeys: self.assetKeysRequiredToPlay) { | |
for key in self.assetKeysRequiredToPlay { | |
var error: NSError? | |
if newAsset.statusOfValue(forKey: key, error: &error) == .failed { | |
self.delegate?.playerDidFailToPlay(message: "Can't use this AVAsset because one of it's keys failed to load") | |
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
func data(from sampleBuffer: CMSampleBuffer) -> Data { | |
var abl = AudioBufferList() | |
var blockBuffer: CMBlockBuffer? | |
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, | |
bufferListSizeNeededOut: nil, | |
bufferListOut: &abl, | |
bufferListSize: MemoryLayout<AudioBufferList>.size, | |
blockBufferAllocator: nil, | |
blockBufferMemoryAllocator: nil, |
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
// Image+Trim.swift | |
// | |
// Copyright © 2020 Christopher Zielinski. | |
// https://gist.github.com/chriszielinski/aec9a2f2ba54745dc715dd55f5718177 | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is |
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
val scalacOptions = Seq( | |
"-encoding", | |
"utf-8", // Specify character encoding used by source files. | |
"-Ybackend-parallelism", // | |
"8", | |
"-explaintypes", // Explain type errors in more detail. | |
"-feature", // Emit warning and location for usages of features that should be imported explicitly. | |
"-unchecked", // Enable additional warnings where generated code depends on assumptions. | |
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access. | |
// "-Ymacro-annotations", // Enable support for macro annotations, formerly in macro paradise. |
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
// | |
// Example of Using AVAudioPlayer | |
// to play a buffer of (synthesized) audio samples from memory | |
// by converting a [Float] buffer into an in-memory WAV file | |
// | |
// Copyright © 2019 Ronald H Nicholson Jr. All rights reserved. | |
// (re)Distribution permitted under the 3-clause New BSD license. | |
// | |
import Foundation |
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
public enum Direction { | |
case forward | |
case backward | |
} | |
internal var player: AVPlayer? | |
private var isSeekInProgress = false | |
private var chaseTime = kCMTimeZero | |
private var preferredFrameRate: Float = 23.98 |
NewerOlder