agora_rtc_engine_aac 1.0.0 copy "agora_rtc_engine_aac: ^1.0.0" to clipboard
agora_rtc_engine_aac: ^1.0.0 copied to clipboard

discontinued

Flutter plugin for Agora Video SDK.

example/lib/main.dart

import 'dart:async';
import 'dart:typed_data';

import 'package:agora_rtc_engine/rtc_engine.dart';
import 'package:agora_rtc_engine/rtc_local_view.dart' as RtcLocalView;
import 'package:agora_rtc_engine/rtc_remote_view.dart' as RtcRemoteView;
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _joined = false;
  int _remoteUid = null;
  bool _switch = false;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    await [Permission.camera, Permission.microphone, Permission.storage].request();

    var engine = await RtcEngine.create("2186dc97eda94b819b871404fa728f3c");
    engine.setEventHandler(RtcEngineEventHandler(
      joinChannelSuccess: (String channel, int uid, int elapsed) {
        print('joinChannelSuccess ${channel} ${uid}');
        setState(() {
          _joined = true;
        });
      },
      userJoined: (int uid, int elapsed) {
        print('userJoined ${uid}');
        setState(() {
          _remoteUid = uid;
        });
      },
      userOffline: (int uid, UserOfflineReason reason) {
        print('userOffline ${uid}');
        setState(() {
          _remoteUid = null;
        });
      },
      recordFrameCallback: (Uint8List bytes, int numOfSamples, int bytesPerSample, int channels, int samplesPerSec) {
        ///
        print('recordFrameCallback bytes${bytes.length}');
      },
    ));
    // await engine.enableVideo();
    const token =
        "0062186dc97eda94b819b871404fa728f3cIADZYCGXH5hKI6xEVxk5ysH0Z7WlAq+a9LtzEqWvnf2Sc9JjSIgAAAAAEACVypXN3UjDXwEAAQDdSMNf";
    await engine.joinChannel(token, '123', null, 0);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Stack(
          children: [
            Center(
              child: _switch ? _renderRemoteVideo() : _renderLocalPreview(),
            ),
            Align(
              alignment: Alignment.topLeft,
              child: Container(
                width: 100,
                height: 100,
                color: Colors.blue,
                child: GestureDetector(
                  onTap: () {
                    setState(() {
                      _switch = !_switch;
                    });
                  },
                  child: Center(
                    child: _switch ? _renderLocalPreview() : _renderRemoteVideo(),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _renderLocalPreview() {
    if (_joined) {
      return RtcLocalView.SurfaceView();
    } else {
      return Text(
        'Please join channel first',
        textAlign: TextAlign.center,
      );
    }
  }

  Widget _renderRemoteVideo() {
    if (_remoteUid != null) {
      return RtcRemoteView.SurfaceView(uid: _remoteUid);
    } else {
      return Text(
        'Please wait remote user join',
        textAlign: TextAlign.center,
      );
    }
  }
}
0
likes
30
pub points
0%
popularity

Publisher

unverified uploader

Flutter plugin for Agora Video SDK.

Homepage
Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter, json_annotation

More

Packages that depend on agora_rtc_engine_aac