void enableTRTCAudioFrameDelegate() {TRTCCloud.sharedInstance(getApplicationContext()).setAudioFrameListener(new AudioFrameListener());result.success("");}void disableTRTCAudioFrameDelegate() {TRTCCloud.sharedInstance(getApplicationContext()).setAudioFrameListener(null);result.success("");}class AudioFrameListener implements TRTCCloudListener.TRTCAudioFrameListener {@Overridepublic void onCapturedAudioFrame(TRTCCloudDef.TRTCAudioFrame trtcAudioFrame) {// TODO}@Overridepublic void onLocalProcessedAudioFrame(TRTCCloudDef.TRTCAudioFrame trtcAudioFrame) {// TODO}@Overridepublic void onRemoteUserAudioFrame(TRTCCloudDef.TRTCAudioFrame trtcAudioFrame, String s) {// TODO}@Overridepublic void onMixedPlayAudioFrame(TRTCCloudDef.TRTCAudioFrame trtcAudioFrame) {// TODO}@Overridepublic void onMixedAllAudioFrame(TRTCCloudDef.TRTCAudioFrame trtcAudioFrame) {// TODO}@Overridepublic void onVoiceEarMonitorAudioFrame(TRTCCloudDef.TRTCAudioFrame trtcAudioFrame) {// TODO}}
let listener = AudioFrameProcessListener()func enableTRTCAudioFrameDelegate() {TRTCCloud.sharedInstance().setAudioFrameDelegate(listener)result(nil)}func disableTRTCAudioFrameDelegate() {TRTCCloud.sharedInstance().setAudioFrameDelegate(nil)result(nil)}class AudioFrameProcessListener: NSObject, TRTCAudioFrameDelegate {func onCapturedAudioFrame(_ frame: TRTCAudioFrame) {//MARK: TODO}func onLocalProcessedAudioFrame(_ frame: TRTCAudioFrame) {// MARK: TODO}func onRemoteUserAudioFrame(_ frame: TRTCAudioFrame, userId: String) {// MARK: TODO}func onMixedAllAudioFrame(_ frame: TRTCAudioFrame) {// MARK: TODO}func onMixedPlay(_ frame: TRTCAudioFrame) {// MARK: TODO}func onVoiceEarMonitorAudioFrame(_ frame: TRTCAudioFrame) {// MARK: TODO}}
final channel = MethodChannel('TRCT_FLUTTER_EXAMPLE');void enableAudioFrame() async {await channel.invokeMethod('enableTRTCAudioFrameDelegate');}void disableAudioFrame() async {await channel.invokeMethod('disableTRTCAudioFrameDelegate');}
public class MainActivity extends FlutterActivity {private static final String channelName = "TRCT_FLUTTER_EXAMPLE";private MethodChannel channel;@Overridepublic void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {super.configureFlutterEngine(flutterEngine);channel = new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), channelName);channel.setMethodCallHandler(((call, result) -> {switch (call.method) {case "enableTRTCAudioFrameDelegate":enableTRTCAudioFrameDelegate();break;case "disableTRTCAudioFrameDelegate":disableTRTCAudioFrameDelegate();break;default:break;}}));}}
@UIApplicationMain@objc class AppDelegate: FlutterAppDelegate {var channel: FlutterMethodChannel?override func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {GeneratedPluginRegistrant.register(with: self)guard let controller = window?.rootViewController as? FlutterViewController else {fatalError("Invalid root view controller")}channel = FlutterMethodChannel(name: "TRCT_FLUTTER_EXAMPLE", binaryMessenger: controller.binaryMessenger)channel?.setMethodCallHandler({ [weak self] call, result inguard let self = self else { return }switch (call.method) {case "enableTRTCAudioFrameDelegate":self.enableTRTCAudioFrameDelegate()breakcase "disableTRTCAudioFrameDelegate":self.disableTRTCAudioFrameDelegate()breakdefault:break}})return super.application(application, didFinishLaunchingWithOptions: launchOptions)}}
TRTCCloud trtcCloud = (await TRTCCloud.sharedInstance())!;// 开启音频原数据获取final audioFrameListener = TRTCAudioFrameListener( onCapturedAudioFrame: (audioFrame) {// TODO } ); trtcCloud.setAudioFrameListener(audioFrameListener);// 停止音频原数据获取trtcCloud.setAudioFrameListener(null);
本页内容是否解决了您的问题?