-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add scene of RTMP, sound effect for SwiftUI
- Loading branch information
qinhui
committed
Oct 9, 2024
1 parent
b3e5a07
commit 61a95a4
Showing
9 changed files
with
600 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
iOS/APIExample-SwiftUI/APIExample-SwiftUI/Examples/Advanced/FusionCDN/FusionCDN.swift
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
iOS/APIExample-SwiftUI/APIExample-SwiftUI/Examples/Advanced/FusionCDN/FusionCDNRTC.swift
This file was deleted.
Oops, something went wrong.
86 changes: 86 additions & 0 deletions
86
iOS/APIExample-SwiftUI/APIExample-SwiftUI/Examples/Advanced/RTMPStream/RTMPStream.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// RTMStream.swift | ||
// APIExample-SwiftUI | ||
// | ||
// Created by qinhui on 2024/10/8. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct RTMPStreamEntry: View { | ||
@State private var channelName: String = "" | ||
@State private var isActive = false | ||
@State private var configs: [String: Any] = [:] | ||
|
||
var body: some View { | ||
VStack { | ||
Spacer() | ||
Text("Ensure that you enable the RTMP Converter service at Agora Dashboard before using this function.") | ||
TextField("Enter channel name".localized, text: $channelName).textFieldStyle(.roundedBorder).padding() | ||
Button { | ||
configs = ["channelName": channelName] | ||
self.isActive = true | ||
} label: { | ||
Text("Join".localized) | ||
}.disabled(channelName.isEmpty) | ||
Spacer() | ||
NavigationLink(destination: RTMPStream(configs: configs).navigationTitle(channelName).navigationBarTitleDisplayMode(.inline), isActive: $isActive) { | ||
EmptyView() | ||
} | ||
Spacer() | ||
} | ||
.padding(.horizontal, 40) | ||
.navigationBarTitleDisplayMode(.inline) | ||
} | ||
} | ||
|
||
struct RTMPStream: View { | ||
@State var configs: [String: Any] = [:] | ||
@ObservedObject private var agoraKit = RTMPStreamRTC() | ||
|
||
var localView = VideoView(type: .local, | ||
audioOnly: false) | ||
var remoteView = VideoView(type: .remote, | ||
audioOnly: false) | ||
|
||
var body: some View { | ||
VStack { | ||
HStack{ | ||
localView | ||
remoteView | ||
}.frame(maxHeight: 200) | ||
|
||
if agoraKit.isJoined { | ||
VStack { | ||
HStack { | ||
TextField("", text: $agoraKit.rtmpUrl) | ||
.disabled(agoraKit.isPublished) | ||
|
||
Button(agoraKit.isPublished ? "stopPublish".localized : "Publish".localized) { | ||
agoraKit.onPublish() | ||
} | ||
} | ||
HStack { | ||
Spacer() | ||
Toggle("Transcoding".localized, isOn: $agoraKit.transcodingState) | ||
.disabled(agoraKit.isPublished) | ||
.frame(width: 100) | ||
} | ||
} | ||
.padding(.horizontal, 40) | ||
} | ||
|
||
Spacer() | ||
}.onAppear(perform: { | ||
agoraKit.setupRTC(configs: configs, | ||
localView: localView.videoView, | ||
remoteView: remoteView.videoView) | ||
}).onDisappear(perform: { | ||
agoraKit.onDestory() | ||
}) | ||
} | ||
} | ||
|
||
#Preview { | ||
RTMPStream() | ||
} |
Oops, something went wrong.