Skip to content

Commit 2c1fd90

Browse files
authored
Merge pull request #2 from StreamUI/062624-refactor
Bring back StreamUI and bunch of refactoring
2 parents 9cef7b8 + 0b74f8f commit 2c1fd90

20 files changed

+1709
-999
lines changed

.github/workflows/swift-ci.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
build-and-test:
12+
name: Build & Test on ${{ matrix.os }} with Swift 5.10
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
os: [ubuntu-latest, macos-latest]
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Swift
22+
uses: swift-actions/setup-swift@65540b95f51493d65f5e59e97dcef9629ddf11bf
23+
with:
24+
swift-version: '5.10'
25+
26+
- name: Build
27+
run: swift build
28+
29+
- name: Run tests
30+
run: swift test

Examples/CLIExample/index.swift

+65-44
Original file line numberDiff line numberDiff line change
@@ -114,51 +114,72 @@ import VideoViews
114114
// Or if you don't want the View to see the rendering with controls you can:
115115
//
116116
//
117-
118117
@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-
// }
118+
struct CLIExample: App {
119+
@Environment(\.displayScale) private var displayScale
161120

162-
// try await Task.sleep(for: .seconds(1.0))
121+
var body: some Scene {
122+
WindowGroup {
123+
StreamUI(
124+
fps: 30,
125+
width: 1080,
126+
height: 1920,
127+
displayScale: displayScale,
128+
// captureDuration: .seconds(5),
129+
saveVideoFile: true
130+
) {
131+
BasicCounterView(initialCounter: 0)
132+
}
133+
}
163134
}
164135
}
136+
137+
// @main
138+
// enum CLIExample {
139+
// static func main() async throws {
140+
// let recorder = createStreamUIRecorder(
141+
// fps: 30,
142+
// width: 1080,
143+
// height: 1920,
144+
// displayScale: 2.0,
145+
// captureDuration: .seconds(7),
146+
// saveVideoFile: true
147+
// ) {
148+
// BasicCounterView(initialCounter: 0)
149+
//// VideoTestView()
150+
//// ImageTestView()
151+
//// SoundTestView()
152+
//// SpriteKitTestView()
153+
//// SceneKitTestView()
154+
// }
155+
//
156+
// let controlledClock = recorder.controlledClock
157+
//
158+
// recorder.startRecording()
159+
//
160+
//// try await Task.sleep(for: .seconds(5))
161+
//// recorder.stopRecording()
162+
// // try await controlledClock.sleep(for: 5.0)
163+
//// recorder.pauseRecording()
164+
//// try await Task.sleep(for: .seconds(10))
165+
// //// try await controlledClock.sleep(for: 10.0)
166+
//// recorder.resumeRecording()
167+
//// recorder.stopRecording()
168+
//// try await Task.sleep(for: .seconds(2))
169+
//// recorder.resumeRecording()
170+
//
171+
// // Wait for the recording to complete
172+
// await recorder.waitForRecordingCompletion()
173+
//
174+
//// while recorder.isRecording {
175+
//// print("while recording")
176+
//// try await Task.sleep(for: .seconds(5))
177+
//// print("waited five secs")
178+
//// recorder.isPaused.toggle()
179+
//// try await Task.sleep(for: .seconds(2))
180+
//// recorder.isPaused.toggle()
181+
//// }
182+
//
183+
//// try await Task.sleep(for: .seconds(1.0))
184+
// }
185+
// }

Examples/VideoViews/BasicCounterView.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public struct BasicCounterView: View {
5454

5555
Task {
5656
print("going to load")
57-
try await recorder?.loadAudio(from: audioUrl)
57+
// try await recorder?.loadAudio(from: audioUrl)
5858
print("loaded audio")
5959

60-
recorder?.playAudio(from: audioUrl)
60+
// recorder?.playAudio(from: audioUrl)
6161
}
6262
// recorder.l
6363
// playAudio()
@@ -83,10 +83,8 @@ public struct BasicCounterView: View {
8383
private func startTimer() {
8484
Task {
8585
while true {
86-
print("TIMER LOOP")
8786
// print("RECORDER COUNT", recorder?.frameCount)
8887
try await recorder?.controlledClock.clock.sleep(for: .seconds(1.0))
89-
print("TIMER LOOP AFETER")
9088
// try await recorder?.clock.sleep(for: .seconds(1.0 / Double(30)))
9189
counter += 1
9290
}

Examples/VideoViews/ImageTestView.swift

+23-5
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,32 @@ import SwiftUI
1111
public struct ImageTestView: View {
1212
@Environment(\.recorder) private var recorder
1313

14-
let url = "https://sample-videos.com/img/Sample-jpg-image-5mb.jpg"
14+
@State private var currentImageIndex = 0
15+
16+
let imageUrls = [
17+
"https://sample-videos.com/img/Sample-jpg-image-5mb.jpg",
18+
"https://mogged-pullzone.b-cdn.net/people/8336bde2-3d36-41c3-a8ad-9c9d5413eff6.jpg?class=mobile",
19+
"https://mogged-pullzone.b-cdn.net/people/0880cf5d-10d1-49b2-b468-e84d19f5bdca.jpg",
20+
"https://mogged-pullzone.b-cdn.net/people/08c08ae7-732e-4966-917f-f94174daa024.jpg",
21+
"https://mogged-pullzone.b-cdn.net/people/0a4f6fc6-bc77-4b4a-9dfb-c690b5931625.jpg"
22+
]
1523

1624
public init() {}
1725
public var body: some View {
18-
StreamingImage(url: URL(string: url)!)
19-
.frame(width: 500, height: 900)
26+
VStack {
27+
StreamingImage(url: URL(string: imageUrls[currentImageIndex])!, scaleType: .fill)
28+
.frame(width: 1080, height: 1920)
29+
.id(currentImageIndex)
30+
}
31+
.onAppear(perform: startTimer)
32+
}
2033

21-
// VideoPlayer(player: AVPlayer(url: URL(string: "https://file-examples.com/storage/fed5266c9966708dcaeaea6/2017/04/file_example_MP4_480_1_5MG.mp4")!))
22-
// .frame(height: 400)
34+
private func startTimer() {
35+
Task {
36+
while true {
37+
try await recorder?.controlledClock.clock.sleep(for: .milliseconds(1000))
38+
currentImageIndex = (currentImageIndex + 1) % imageUrls.count
39+
}
40+
}
2341
}
2442
}

0 commit comments

Comments
 (0)