Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [iOS] Implement custom audio source example #481

Merged
merged 2 commits into from
Oct 27, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// Register the `CustomAudioPlugin` to interect with the `RtcEngine`
RtcEnginePlugin.register(customAudioPlugin)
}

override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
// The `CustomAudioSource` is generated by [pigeon](https://pub.dev/packages/pigeon), you can see the
// the definiton on `example/lib/examples/advanced/custom_audio/custom_audio_source_api.dart`
CustomAudioSource.CustomAudioSourceApi.setup(flutterEngine.dartExecutor, customAudioPlugin)
}

Expand Down
46 changes: 44 additions & 2 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
5E9D826C4B1F29399F8A7742 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28CEF344452C45083E367B0C /* Pods_Runner.framework */; };
6D48449932DC5CD432350C00 /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43CA39DDEDE840FF44D1F750 /* Pods_RunnerTests.framework */; };
7110181B2727DA66003816A9 /* CustomAudioSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 7110181A2727DA66003816A9 /* CustomAudioSource.m */; };
711018242727DE9A003816A9 /* ExternalAudio.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7110181E2727DE9A003816A9 /* ExternalAudio.mm */; };
711018252727DE9A003816A9 /* AudioWriteToFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 711018222727DE9A003816A9 /* AudioWriteToFile.m */; };
711018262727DE9A003816A9 /* AudioController.m in Sources */ = {isa = PBXBuildFile; fileRef = 711018232727DE9A003816A9 /* AudioController.m */; };
711018282727E05A003816A9 /* CustmoAudioSourcePlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711018272727E05A003816A9 /* CustmoAudioSourcePlugin.swift */; };
71E2A2A22722C75F00C7B7BC /* OCTestRtcEnginePlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 71E2A29E2722C75F00C7B7BC /* OCTestRtcEnginePlugin.m */; };
71E2A2A32722C75F00C7B7BC /* FakeAgoraRtcEngineKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71E2A2A02722C75F00C7B7BC /* FakeAgoraRtcEngineKit.swift */; };
71E2A2A52722C80800C7B7BC /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71E2A2A42722C80800C7B7BC /* RunnerTests.swift */; };
Expand Down Expand Up @@ -51,6 +56,16 @@
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
43CA39DDEDE840FF44D1F750 /* Pods_RunnerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RunnerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
592BF9E1006B18851CF75B6B /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = "<group>"; };
711018192727DA66003816A9 /* CustomAudioSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomAudioSource.h; sourceTree = "<group>"; };
7110181A2727DA66003816A9 /* CustomAudioSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomAudioSource.m; sourceTree = "<group>"; };
7110181D2727DE9A003816A9 /* AudioOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioOptions.h; sourceTree = "<group>"; };
7110181E2727DE9A003816A9 /* ExternalAudio.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ExternalAudio.mm; sourceTree = "<group>"; };
7110181F2727DE9A003816A9 /* ExternalAudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExternalAudio.h; sourceTree = "<group>"; };
711018202727DE9A003816A9 /* AudioWriteToFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioWriteToFile.h; sourceTree = "<group>"; };
711018212727DE9A003816A9 /* AudioController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioController.h; sourceTree = "<group>"; };
711018222727DE9A003816A9 /* AudioWriteToFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AudioWriteToFile.m; sourceTree = "<group>"; };
711018232727DE9A003816A9 /* AudioController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AudioController.m; sourceTree = "<group>"; };
711018272727E05A003816A9 /* CustmoAudioSourcePlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustmoAudioSourcePlugin.swift; sourceTree = "<group>"; };
71E2A2932722C73000C7B7BC /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
71E2A29E2722C75F00C7B7BC /* OCTestRtcEnginePlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCTestRtcEnginePlugin.m; sourceTree = "<group>"; };
71E2A29F2722C75F00C7B7BC /* OCTestRtcEnginePlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCTestRtcEnginePlugin.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -115,6 +130,23 @@
name = Frameworks;
sourceTree = "<group>";
};
711018292727FFF1003816A9 /* CustomAudioSource */ = {
isa = PBXGroup;
children = (
711018212727DE9A003816A9 /* AudioController.h */,
711018232727DE9A003816A9 /* AudioController.m */,
7110181D2727DE9A003816A9 /* AudioOptions.h */,
711018202727DE9A003816A9 /* AudioWriteToFile.h */,
711018222727DE9A003816A9 /* AudioWriteToFile.m */,
7110181F2727DE9A003816A9 /* ExternalAudio.h */,
7110181E2727DE9A003816A9 /* ExternalAudio.mm */,
711018192727DA66003816A9 /* CustomAudioSource.h */,
7110181A2727DA66003816A9 /* CustomAudioSource.m */,
711018272727E05A003816A9 /* CustmoAudioSourcePlugin.swift */,
);
path = CustomAudioSource;
sourceTree = "<group>";
};
71E2A2942722C73000C7B7BC /* RunnerTests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -162,6 +194,7 @@
97C146F01CF9000F007C117D /* Runner */ = {
isa = PBXGroup;
children = (
711018292727FFF1003816A9 /* CustomAudioSource */,
97C146FA1CF9000F007C117D /* Main.storyboard */,
97C146FD1CF9000F007C117D /* Assets.xcassets */,
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -394,6 +427,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
711018262727DE9A003816A9 /* AudioController.m in Sources */,
7110181B2727DA66003816A9 /* CustomAudioSource.m in Sources */,
711018252727DE9A003816A9 /* AudioWriteToFile.m in Sources */,
711018242727DE9A003816A9 /* ExternalAudio.mm in Sources */,
711018282727E05A003816A9 /* CustmoAudioSourcePlugin.swift in Sources */,
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
);
Expand Down Expand Up @@ -472,8 +510,9 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand Down Expand Up @@ -669,7 +708,9 @@
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = NO;
};
name = Debug;
};
Expand Down Expand Up @@ -716,8 +757,9 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
30 changes: 25 additions & 5 deletions example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,31 @@ import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(

private var customAudioSourcePlugin: CustomAudioPlugin!

override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
) -> Bool {
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController

customAudioSourcePlugin = CustomAudioPlugin()
littleGnAl marked this conversation as resolved.
Show resolved Hide resolved

// The `CustomAudioSourceApiSetup` is generated by [pigeon](https://pub.dev/packages/pigeon), you can see the
// the definiton on `example/lib/examples/advanced/custom_audio/custom_audio_source_api.dart`
CustomAudioSourceApiSetup(
controller.binaryMessenger, customAudioSourcePlugin)

// Register the `CustomAudioPlugin` to interect with the `AgoraRtcEngineKit`
RtcEnginePluginRegistrant.register(customAudioSourcePlugin)

GeneratedPluginRegistrant.register(with: self)

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

override func applicationWillTerminate(_ application: UIApplication) {
RtcEnginePluginRegistrant.unregister(customAudioSourcePlugin)
}
}
35 changes: 35 additions & 0 deletions example/ios/Runner/CustomAudioSource/AudioController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// AudioController.h
// AudioCapture
//
// Created by CavanSu on 10/11/2017.
// Copyright © 2017 Agora. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import "AudioOptions.h"

@class AudioController;
@protocol AudioControllerDelegate <NSObject>
@optional
- (void)audioController:(AudioController *)controller
didCaptureData:(unsigned char *)data
bytesLength:(int)bytesLength;
- (int)audioController:(AudioController *)controller
didRenderData:(unsigned char *)data
bytesLength:(int)bytesLength;
- (void)audioController:(AudioController *)controller
error:(OSStatus)error
info:(NSString *)info;
@end


@interface AudioController : NSObject
@property (nonatomic, weak) id<AudioControllerDelegate> delegate;

+ (instancetype)audioController;
- (void)setUpAudioSessionWithSampleRate:(int)sampleRate channelCount:(int)channelCount audioCRMode:(AudioCRMode)audioCRMode IOType:(IOUnitType)ioType;
- (void)startWork;
- (void)stopWork;
@end
Loading