Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.caf filter=lfs diff=lfs merge=lfs -text

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions LiveKitExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 56;
objectVersion = 70;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -101,6 +101,21 @@
D7AA477A285A0FFC00EB41AE /* SampleHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleHandler.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
689958FD2EB4B9C20037CECF /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
"tadaa-mono.caf",
"tadaa-stereo.caf",
);
target = 68A50E8E2C4C1C4C00D2DE17 /* LiveKitExample */;
};
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */

/* Begin PBXFileSystemSynchronizedRootGroup section */
684A6D8A2EB40C1A00FF6EB1 /* Resources */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (689958FD2EB4B9C20037CECF /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = Resources; sourceTree = "<group>"; };
/* End PBXFileSystemSynchronizedRootGroup section */

/* Begin PBXFrameworksBuildPhase section */
683F05F0273F96B20080C7AC /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
Expand Down Expand Up @@ -210,6 +225,7 @@
68B38536271E780600711D5F = {
isa = PBXGroup;
children = (
684A6D8A2EB40C1A00FF6EB1 /* Resources */,
68A50EDE2C4C1ED500D2DE17 /* Multiplatform */,
6865EA2427513B4500FFAFC3 /* iOS */,
68B38544271E780700711D5F /* Products */,
Expand Down Expand Up @@ -754,8 +770,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/livekit/client-sdk-swift";
requirement = {
kind = exactVersion;
version = 2.8.1;
branch = "hiroshi/sound-player";
kind = branch;
};
};
B5C2EF142D0114C800FAC766 /* XCRemoteSwiftPackageReference "components-swift" */ = {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions Multiplatform/Controllers/AppContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
* limitations under the License.
*/

import AVFAudio
import Combine
import LiveKit
import SwiftUI

let soundPlayer = SoundPlayer()

nonisolated(unsafe) var audioPlayer: AVAudioPlayer?

// This class contains the logic to control behavior of the whole app.
@MainActor
final class AppContext: ObservableObject {
Expand Down Expand Up @@ -95,6 +100,21 @@ final class AppContext: ObservableObject {
didSet { AudioManager.shared.mixer.appVolume = appVolume }
}

func playSoundEffectNormal() async throws {
guard let url = Bundle.main.url(forResource: "tadaa-mono", withExtension: "caf") else {
throw NSError(domain: "Audio", code: 1, userInfo: [NSLocalizedDescriptionKey: "tadaa.caf not found in bundle"])
}

// Create and play the audio player
audioPlayer = try AVAudioPlayer(contentsOf: url)
audioPlayer?.prepareToPlay()
audioPlayer?.play()
}

func playSoundEffectAPI() async throws {
try await soundPlayer.play(id: "tadaa")
}

init(store: ValueStore<Preferences>) {
self.store = store

Expand All @@ -121,5 +141,18 @@ final class AppContext: ObservableObject {
inputDevices = AudioManager.shared.inputDevices
outputDevice = AudioManager.shared.outputDevice
inputDevice = AudioManager.shared.inputDevice

// Prepare audio effects

if let audioUrl = Bundle.main.url(forResource: "tadaa-mono", withExtension: "caf") {
Task {
do {
try soundPlayer.prepare(url: audioUrl, withId: "tadaa")
try await soundPlayer.startEngine()
} catch {
print("Error preparing sound: \(error)")
}
}
}
}
}
7 changes: 1 addition & 6 deletions Multiplatform/LiveKitExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import KeychainAccess
import LiveKit
import Logging
import SwiftUI

@MainActor let sync = ValueStore<Preferences>(store: Keychain(service: "io.livekit.example.SwiftSDK.1"),
Expand Down Expand Up @@ -53,10 +52,6 @@ struct LiveKitExample: App {
}

init() {
LoggingSystem.bootstrap {
var logHandler = StreamLogHandler.standardOutput(label: $0)
logHandler.logLevel = .debug
return logHandler
}
LiveKitSDK.setLogLevel(.debug)
}
}
18 changes: 18 additions & 0 deletions Multiplatform/Views/AudioMixerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ struct AudioMixerView: View {
Text("App")
Slider(value: $appCtx.appVolume, in: 0.0 ... 1.0)
}
Button("Play sound effect (Normal)") {
Task {
do {
try await appCtx.playSoundEffectNormal()
} catch {
print("Failed to play sound effect: \(error)")
}
}
}
Button("Play sound effect (API)") {
Task {
do {
try await appCtx.playSoundEffectAPI()
} catch {
print("Failed to play sound effect: \(error)")
}
}
}
}
}
#endif
9 changes: 4 additions & 5 deletions Multiplatform/Views/RoomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,11 @@ struct RoomView: View {
} label: {
Image(systemSymbol: .switch2)
}
.disabled(!isMicrophoneEnabled)
#if !os(tvOS)
.popover(isPresented: $audioMixerOptionsPresented) {
AudioMixerView()
.padding()
}
.popover(isPresented: $audioMixerOptionsPresented) {
AudioMixerView()
.padding()
}
#endif

#if os(iOS)
Expand Down
3 changes: 3 additions & 0 deletions Resources/tadaa-mono.caf
Git LFS file not shown
3 changes: 3 additions & 0 deletions Resources/tadaa-stereo.caf
Git LFS file not shown