Skip to content

Commit

Permalink
add scene of RTMP, sound effect for SwiftUI
Browse files Browse the repository at this point in the history
  • Loading branch information
qinhui committed Oct 9, 2024
1 parent b3e5a07 commit 61a95a4
Show file tree
Hide file tree
Showing 9 changed files with 600 additions and 105 deletions.
22 changes: 11 additions & 11 deletions iOS/APIExample-SwiftUI/APIExample-SwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@
F728BA102CA6D5E9007813BB /* RawVideoData.swift in Sources */ = {isa = PBXBuildFile; fileRef = F728BA0F2CA6D5E9007813BB /* RawVideoData.swift */; };
F728BA132CA9074B007813BB /* LocalVideoTranscoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = F728BA122CA9074B007813BB /* LocalVideoTranscoding.swift */; };
F728BA152CA9075D007813BB /* LocalVideoTranscodingRTC.swift in Sources */ = {isa = PBXBuildFile; fileRef = F728BA142CA9075D007813BB /* LocalVideoTranscodingRTC.swift */; };
F728BA1B2CA93B29007813BB /* FusionCDNRTC.swift in Sources */ = {isa = PBXBuildFile; fileRef = F728BA1A2CA93B29007813BB /* FusionCDNRTC.swift */; };
F728BA1D2CA93B34007813BB /* FusionCDN.swift in Sources */ = {isa = PBXBuildFile; fileRef = F728BA1C2CA93B34007813BB /* FusionCDN.swift */; };
F728BA202CA93EEF007813BB /* VoiceChanger.swift in Sources */ = {isa = PBXBuildFile; fileRef = F728BA1F2CA93EEF007813BB /* VoiceChanger.swift */; };
F728BA222CA93EF9007813BB /* VoiceChangerRTC.swift in Sources */ = {isa = PBXBuildFile; fileRef = F728BA212CA93EF9007813BB /* VoiceChangerRTC.swift */; };
F728BA2E2CB53E04007813BB /* RTMPStreamRTC.swift in Sources */ = {isa = PBXBuildFile; fileRef = F728BA2D2CB53E04007813BB /* RTMPStreamRTC.swift */; };
F728BA302CB53E13007813BB /* RTMPStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = F728BA2F2CB53E13007813BB /* RTMPStream.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -312,10 +312,10 @@
F728BA0F2CA6D5E9007813BB /* RawVideoData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RawVideoData.swift; sourceTree = "<group>"; };
F728BA122CA9074B007813BB /* LocalVideoTranscoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalVideoTranscoding.swift; sourceTree = "<group>"; };
F728BA142CA9075D007813BB /* LocalVideoTranscodingRTC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalVideoTranscodingRTC.swift; sourceTree = "<group>"; };
F728BA1A2CA93B29007813BB /* FusionCDNRTC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FusionCDNRTC.swift; sourceTree = "<group>"; };
F728BA1C2CA93B34007813BB /* FusionCDN.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FusionCDN.swift; sourceTree = "<group>"; };
F728BA1F2CA93EEF007813BB /* VoiceChanger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VoiceChanger.swift; sourceTree = "<group>"; };
F728BA212CA93EF9007813BB /* VoiceChangerRTC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VoiceChangerRTC.swift; sourceTree = "<group>"; };
F728BA2D2CB53E04007813BB /* RTMPStreamRTC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RTMPStreamRTC.swift; sourceTree = "<group>"; };
F728BA2F2CB53E13007813BB /* RTMPStream.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RTMPStream.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -477,7 +477,7 @@
isa = PBXGroup;
children = (
F728BA1E2CA93EDA007813BB /* VoiceChanger */,
F728BA162CA9398E007813BB /* FusionCDN */,
F728BA162CA9398E007813BB /* RTMPStream */,
F728BA112CA90732007813BB /* LocalVideoTranscoding */,
F728BA0C2CA6D5CE007813BB /* RawVideoData */,
F728BA072CA6C1D6007813BB /* RawAudioData */,
Expand Down Expand Up @@ -900,13 +900,13 @@
path = LocalVideoTranscoding;
sourceTree = "<group>";
};
F728BA162CA9398E007813BB /* FusionCDN */ = {
F728BA162CA9398E007813BB /* RTMPStream */ = {
isa = PBXGroup;
children = (
F728BA1A2CA93B29007813BB /* FusionCDNRTC.swift */,
F728BA1C2CA93B34007813BB /* FusionCDN.swift */,
F728BA2D2CB53E04007813BB /* RTMPStreamRTC.swift */,
F728BA2F2CB53E13007813BB /* RTMPStream.swift */,
);
path = FusionCDN;
path = RTMPStream;
sourceTree = "<group>";
};
F728BA1E2CA93EDA007813BB /* VoiceChanger */ = {
Expand Down Expand Up @@ -1100,8 +1100,8 @@
E73F24832BA851870000B523 /* AgoraMetalShader.metal in Sources */,
F70DE5372C6B6DC900FFC922 /* PixelBufferRenderView.swift in Sources */,
E73F247B2BA851870000B523 /* UIView+CSshortFrame.m in Sources */,
F728BA1B2CA93B29007813BB /* FusionCDNRTC.swift in Sources */,
E73F24022BA82C440000B523 /* ContentView.swift in Sources */,
F728BA302CB53E13007813BB /* RTMPStream.swift in Sources */,
E73F24852BA851870000B523 /* AgoraYUVImageSourcePush.m in Sources */,
E71D54642BCCD14800656537 /* MediaPlayer.swift in Sources */,
F728BA152CA9075D007813BB /* LocalVideoTranscodingRTC.swift in Sources */,
Expand Down Expand Up @@ -1149,6 +1149,7 @@
E71D54732BCD270800656537 /* StreamEncryption.swift in Sources */,
E73F24E72BB519600000B523 /* CreateDataStreamRTC.swift in Sources */,
E71D54692BCD075700656537 /* PrecallTest.swift in Sources */,
F728BA2E2CB53E04007813BB /* RTMPStreamRTC.swift in Sources */,
E73F24BD2BAD89920000B523 /* AudioWaveform.swift in Sources */,
E73F24002BA82C440000B523 /* APIExample_SwiftUIApp.swift in Sources */,
E73F24F62BB66F5F0000B523 /* VideoProcess.swift in Sources */,
Expand Down Expand Up @@ -1196,7 +1197,6 @@
E73F24A02BA997E30000B523 /* JoinChannelVideo.swift in Sources */,
E73F24C52BB152450000B523 /* ARKitRTC.swift in Sources */,
E73F247C2BA851870000B523 /* ExternalAudio.mm in Sources */,
F728BA1D2CA93B34007813BB /* FusionCDN.swift in Sources */,
E73F24BC2BAD89920000B523 /* AudioWaveformRTC.swift in Sources */,
F728BA132CA9074B007813BB /* LocalVideoTranscoding.swift in Sources */,
E73F251C2BB6B22B0000B523 /* ScreenShare.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions iOS/APIExample-SwiftUI/APIExample-SwiftUI/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct ContentView: View {
view: AnyView(LocalVideoTranscodingEntry())),
MenuItem(name: "Voice Changer".localized,
view: AnyView(VoiceChangerEntry())),
MenuItem(name: "RTMP Streaming".localized,
view: AnyView(RTMPStreamEntry())),
MenuItem(name: "Picture In Picture".localized,
view: AnyView(PictureInPictureEntry())),
MenuItem(name: "Quick Switch Channel".localized,
Expand Down

This file was deleted.

This file was deleted.

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()
}
Loading

0 comments on commit 61a95a4

Please sign in to comment.