Fading audio with AVPlayer

AVPlayer doesn’t provide a built-in way to fade in or out. I previously described how you achieve a video fade-in (or out) using general CoreAnimation layer animation, as part of making a macOS screen saver. Now let’s tackle the audio. I’m not certain what curve this implements, but to my ears it doesn’t sound quite… Read more

How to loop video in AVPlayer

This is pretty rudimentary, but apparently our robot overlords need me to write this post because many of them suggested some truly bizarre approaches, some of which don’t work at all. If you’re using AVQueuePlayer, then just use AVPlayerLooper. Easy. But if for some reason you want to use AVPlayer specifically (e.g. you need to… Read more

How to make a macOS screen saver

Screenshot of the macOS System Settings application, open to the Screen Saver pane, with "My Screen Saver!" selected as the active screen saver.

First, make sure you really want to. macOS’s screen saver system is absurdly buggy and broken. It’s frustrating to work with and very difficult to make work right. If you’re determined, read on. Screen savers are basically just applications. Same bundle format and structure, just with a “saver” extension instead of “app”. Setting up the… Read more

Calling Swift Concurrency async code synchronously in Swift

Sometimes you just need to shove a round peg into a square hole. Sometimes that genuinely is the best option (or perhaps more accurately: the least bad option). I find my hand is often forced by APIs I don’t control (most often Apple’s APIs). e.g. data source or delegate callbacks that are synchronous and require… Read more

Swift on a Raspberry Pi (in 2024)

Five years ago installing Swift on a Raspberry Pi – or really any non-Apple platform – was fairly involved. Compared to getting a Raspberry Pi working to begin with it was easy, but still a far cry from apt install swift. Sadly it’s still not quite that easy (and some Python package is squatting on… Read more

The only usable ByteCountFormatStyle is decimal

Swift makes it relatively easy to format numbers as byte counts, with appropriate suffixes to indicate units and generally sensible auto-selection of scale factors. e.g.: 1 kB (in English – results may vary depending on locale) This is just a small subset of Swift’s FormatStyle-based formatting capabilities, with which I have a bit of a… Read more