Skip to content

A Swift learning project that demonstrates building a modern macOS video recording application using SwiftUI and AVFoundation.

Notifications You must be signed in to change notification settings

wscld/macstories

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MacStories Video Recorder

A Swift learning project that demonstrates building a modern macOS video recording application using SwiftUI and AVFoundation.

πŸ“‹ Project Overview

This project is designed as a hands-on learning experience for Swift development on macOS. It implements a sleek, translucent video recording app that captures video and audio from connected devices.

🎯 Learning Objectives

This project covers essential Swift and macOS development concepts:

  • SwiftUI Framework: Modern declarative UI development
  • AVFoundation: Media capture and processing
  • macOS App Development: Native macOS application structure
  • State Management: Using @StateObject, @Published, and @ObservableObject
  • Permissions Handling: Camera and microphone access requests
  • Custom UI Components: Translucent backgrounds and custom views
  • Window Management: Custom window styling and behavior
  • Audio Visualization: Real-time audio level monitoring

πŸ—οΈ Architecture

Core Components

MacStoriesApp.swift

  • Main app entry point using @main attribute
  • Custom AppDelegate for window management
  • Shared app state using ObservableObject
  • Translucent background implementation with NSVisualEffectView

VideoRecorder.swift

  • Core recording functionality using AVCaptureSession
  • Device discovery and management (cameras/microphones)
  • Permission handling for camera and microphone access
  • Real-time audio level monitoring
  • Recording state management

Views/

  • ContentView.swift: Main interface with video preview
  • PermissionsView.swift: Elegant permission request flow
  • AudioWaveView.swift: Visual audio level representation
  • AboutView.swift: Application information
  • IntroView.swift: App introduction flow

Controllers/

  • Window controllers for modular UI management
  • Separation of concerns for different app windows

πŸš€ Features Implemented

βœ… Core Functionality

  • Video recording with selectable cameras
  • Audio recording with device selection
  • Real-time preview with mirroring
  • Permission request workflow
  • Device discovery and switching
  • Recording duration controls
  • Audio level visualization

βœ… UI/UX Features

  • Translucent, modern interface
  • Fixed window size (340x730)
  • Custom title bar styling
  • Smooth animations and transitions
  • Device picker interface
  • Recording controls

βœ… macOS Integration

  • Native permission dialogs
  • System menu integration
  • Keyboard shortcuts
  • Window management

πŸ› οΈ Technical Concepts Demonstrated

1. SwiftUI State Management

@StateObject private var recorder = VideoRecorder()
@Published var isRecording = false
@EnvironmentObject private var appState: AppState

2. AVFoundation Integration

private var captureSession: AVCaptureSession?
private var movieOutput: AVCaptureMovieFileOutput?
let preview = AVCaptureVideoPreviewLayer(session: session)

3. Permission Handling

switch AVCaptureDevice.authorizationStatus(for: .video) {
case .authorized: // Handle authorized state
case .notDetermined: // Request permission
case .denied, .restricted: // Handle denied state
}

4. Custom NSViewRepresentable

struct TranslucentBackgroundView: NSViewRepresentable {
    func makeNSView(context: Context) -> NSVisualEffectView {
        let view = NSVisualEffectView()
        view.material = .dark
        view.blendingMode = .behindWindow
        return view
    }
}

πŸ“š Swift Concepts Covered

Language Features

  • Classes and Structs
  • Protocols and Extensions
  • Optionals and Error Handling
  • Closures and Completion Handlers
  • Property Wrappers (@Published, @StateObject, etc.)

Frameworks & APIs

  • SwiftUI: Views, Modifiers, State Management
  • AVFoundation: Capture Sessions, Device Management
  • Foundation: Timers, Notifications, Data Types
  • AppKit: Window Management, Visual Effects

Design Patterns

  • MVVM (Model-View-ViewModel)
  • Observer Pattern with Combine
  • Delegation Pattern
  • Singleton Pattern (for window controllers)

πŸ”§ Development Environment

  • Language: Swift 5.x
  • Framework: SwiftUI
  • Platform: macOS 11.0+
  • IDE: Xcode 12.0+

πŸ“– Learning Path Suggestions

Beginner Focus Areas

  1. Study ContentView.swift for SwiftUI basics
  2. Examine state management in VideoRecorder.swift
  3. Understand permission flow in PermissionsView.swift

Intermediate Topics

  1. Custom UI components and animations
  2. AVFoundation session management
  3. Window styling and AppDelegate integration

Advanced Concepts

  1. Performance optimization for video capture
  2. Custom visual effects and graphics
  3. Audio processing and visualization

🎨 UI Design Elements

  • Translucent Design: Modern glass-morphism effect
  • Fixed Dimensions: iPhone-like aspect ratio (340x730)
  • Dark Theme: Optimized for video content
  • Smooth Animations: Bouncy transitions and scaling effects
  • Native Controls: macOS-style buttons and interfaces

πŸ”’ Privacy & Permissions

The app demonstrates proper handling of sensitive permissions:

  • Camera access for video recording
  • Microphone access for audio capture
  • Graceful error handling for denied permissions
  • User-friendly permission request flow

🚧 Potential Enhancements for Further Learning

  • Add video filters and effects
  • Implement video editing capabilities
  • Add export format options
  • Create settings persistence
  • Add recording quality selection
  • Implement batch recording features
  • Add cloud storage integration

πŸ“ Notes for Learners

This project serves as an excellent foundation for understanding:

  • How modern macOS apps are structured
  • Integration between Swift UI and system frameworks
  • Real-world permission and device handling
  • Professional UI/UX design patterns in Swift

The codebase is well-organized and includes proper separation of concerns, making it easy to understand and extend as you continue your Swift learning journey.


Created: March 25, 2025
Purpose: Swift Learning Project
Platform: macOS
Framework: SwiftUI + AVFoundation

About

A Swift learning project that demonstrates building a modern macOS video recording application using SwiftUI and AVFoundation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages