|
| 1 | +import AppKit |
| 2 | +import ArgumentParser |
| 3 | +import Foundation |
| 4 | +import StreamUI |
| 5 | +import SwiftUI |
| 6 | +import VideoViews |
| 7 | + |
| 8 | +// @Observable |
| 9 | +// class StreamUISettings { |
| 10 | +// var fps: Int32 = 30 |
| 11 | +// var width: CGFloat = 1080 |
| 12 | +// var height: CGFloat = 1920 |
| 13 | +// var captureDuration: Int = 20 |
| 14 | +// var saveVideoFile: Bool = true |
| 15 | +// |
| 16 | +// var livestreamSettings: [LivestreamSettings] = [] |
| 17 | +// } |
| 18 | +// |
| 19 | +//// Define the command line arguments |
| 20 | +// struct StreamUICLIArgs: ParsableArguments { |
| 21 | +// @Option(help: "Frames per second") |
| 22 | +// var fps: Int |
| 23 | +// |
| 24 | +// @Option(help: "Width of the video") |
| 25 | +// var width: Int |
| 26 | +// |
| 27 | +// @Option(help: "Height of the video") |
| 28 | +// var height: Int |
| 29 | +// |
| 30 | +// @Option(help: "Capture duration in seconds") |
| 31 | +// var captureDuration: Int |
| 32 | +// |
| 33 | +// @Flag(help: "Save video file") |
| 34 | +// var saveVideoFile: Bool = false |
| 35 | +// |
| 36 | +// @Option(help: "RTMP connection URL") |
| 37 | +// var rtmpConnection: String? |
| 38 | +// |
| 39 | +// @Option(help: "Stream key") |
| 40 | +// var streamKey: String? |
| 41 | +// } |
| 42 | +// |
| 43 | +// extension StreamUICLIArgs { |
| 44 | +// func update(_ settings: StreamUISettings) { |
| 45 | +// settings.fps = Int32(fps) |
| 46 | +// settings.width = CGFloat(width) |
| 47 | +// settings.height = CGFloat(height) |
| 48 | +// |
| 49 | +// settings.captureDuration = captureDuration |
| 50 | +// settings.saveVideoFile = saveVideoFile |
| 51 | +// |
| 52 | +// if let rtmpConnection = rtmpConnection, let streamKey = streamKey { |
| 53 | +// let livestreamSettings = LivestreamSettings( |
| 54 | +// rtmpConnection: rtmpConnection, |
| 55 | +// streamKey: streamKey |
| 56 | +// ) |
| 57 | +// settings.livestreamSettings.append(livestreamSettings) |
| 58 | +// } |
| 59 | +// } |
| 60 | +// } |
| 61 | +// |
| 62 | +// @main |
| 63 | +// struct CLIExample: App { |
| 64 | +// @Environment(\.displayScale) private var displayScale |
| 65 | +// |
| 66 | +// @State private var settings: StreamUISettings = { |
| 67 | +// let settings = StreamUISettings() |
| 68 | +// if CommandLine.argc > 1 { |
| 69 | +// do { |
| 70 | +// let args = try StreamUICLIArgs.parse() |
| 71 | +// args.update(settings) |
| 72 | +// } catch { |
| 73 | +// print("Error: Could not parse arguments") |
| 74 | +// print(CommandLine.arguments.dropFirst().joined(separator: " ")) |
| 75 | +// print(StreamUICLIArgs.helpMessage()) |
| 76 | +// exit(1) // Exit if argument parsing fails |
| 77 | +// } |
| 78 | +// } else { |
| 79 | +// settings.fps = 30 |
| 80 | +// settings.width = 1080 |
| 81 | +// settings.height = 1920 |
| 82 | +// settings.captureDuration = 15 |
| 83 | +// settings.saveVideoFile = true |
| 84 | +// settings.livestreamSettings = [ |
| 85 | +// .init(rtmpConnection: "rtmp://localhost/live", streamKey: "streamKey") |
| 86 | +// ] |
| 87 | +// } |
| 88 | +// return settings |
| 89 | +// }() |
| 90 | +// |
| 91 | +// var body: some Scene { |
| 92 | +// WindowGroup { |
| 93 | +// StreamUI( |
| 94 | +// fps: settings.fps, |
| 95 | +// width: settings.width, |
| 96 | +// height: settings.height, |
| 97 | +// displayScale: displayScale, |
| 98 | +//// captureDuration: .seconds(settings.captureDuration), |
| 99 | +// saveVideoFile: settings.saveVideoFile, |
| 100 | +// livestreamSettings: settings.livestreamSettings |
| 101 | +// ) { |
| 102 | +// BasicCounterView(initialCounter: 0) |
| 103 | +//// SpriteKitTestView() |
| 104 | +//// SimpleWebView() |
| 105 | +//// VideoTestView() |
| 106 | +//// RandomSwiftUIComponentsTestView() |
| 107 | +// } |
| 108 | +// } |
| 109 | +// } |
| 110 | +// } |
| 111 | + |
| 112 | +// |
| 113 | +// |
| 114 | +// Or if you don't want the View to see the rendering with controls you can: |
| 115 | +// |
| 116 | +// |
| 117 | + |
| 118 | +@main |
| 119 | +enum CLIExample { |
| 120 | + static func main() async throws { |
| 121 | + print("huhu") |
| 122 | + let recorder = createStreamUIRecorder( |
| 123 | + fps: 30, |
| 124 | + width: 1080, |
| 125 | + height: 1920, |
| 126 | + displayScale: 2.0, |
| 127 | + captureDuration: .seconds(10), |
| 128 | + saveVideoFile: true |
| 129 | + ) { |
| 130 | +// BasicCounterView(initialCounter: 0) |
| 131 | +// VideoTestView() |
| 132 | +// ImageTestView() |
| 133 | + SoundTestView() |
| 134 | + } |
| 135 | + |
| 136 | + let controlledClock = recorder.controlledClock |
| 137 | + |
| 138 | + recorder.startRecording() |
| 139 | + |
| 140 | +// try await Task.sleep(for: .seconds(5)) |
| 141 | + //// try await controlledClock.sleep(for: 5.0) |
| 142 | +// recorder.pauseRecording() |
| 143 | +// try await Task.sleep(for: .seconds(10)) |
| 144 | + //// try await controlledClock.sleep(for: 10.0) |
| 145 | +// recorder.resumeRecording() |
| 146 | +// recorder.stopRecording() |
| 147 | +// try await Task.sleep(for: .seconds(2)) |
| 148 | +// recorder.resumeRecording() |
| 149 | + |
| 150 | + // Wait for the recording to complete |
| 151 | + await recorder.waitForRecordingCompletion() |
| 152 | + |
| 153 | +// while recorder.isRecording { |
| 154 | +// print("while recording") |
| 155 | +// try await Task.sleep(for: .seconds(5)) |
| 156 | +// print("waited five secs") |
| 157 | +// recorder.isPaused.toggle() |
| 158 | +// try await Task.sleep(for: .seconds(2)) |
| 159 | +// recorder.isPaused.toggle() |
| 160 | +// } |
| 161 | + |
| 162 | +// try await Task.sleep(for: .seconds(1.0)) |
| 163 | + } |
| 164 | +} |
0 commit comments