dive_ui 0.2.0 copy "dive_ui: ^0.2.0" to clipboard
dive_ui: ^0.2.0 copied to clipboard

PlatformmacOS

The Dive UI widgets. A toolkit for video recording and streaming.

example/lib/main.dart

import 'dart:io';

import 'package:dive/dive.dart';

/// Dive Example
void main() async {
  configDiveApp();

  print('Dive Example');

  var n = 0;
  ProcessSignal.sigint.watch().listen((signal) {
    print(" caught ${++n} of 3");

    if (n == 3) {
      exit(0);
    }
  });

  await DiveExample()
    ..run();
}

class DiveExample {
  final _elements = DiveCoreElements();
  final _diveCore = DiveCore();
  bool _initialized = false;

  void run() async {
    await _initialize();
  }

  Future<void> _initialize() async {
    if (_initialized) return;
    _initialized = true;

    await _diveCore.setupOBS(DiveCoreResolution.HD);

    // Create the main scene.
    _elements.addScene(DiveScene.create());

    // Create the main audio source
    DiveAudioSource.create('main audio').then((source) {
      if (source != null) {
        _elements.addAudioSource(source);
        _elements.state.currentScene?.addSource(source);
      }
    });

    // Get the first video input
    final videoInput = DiveInputs.video().last;
    print(videoInput);

    // Create the last video source from the video input
    DiveVideoSource.create(videoInput).then((source) {
      if (source != null) {
        _elements.addVideoSource(source);
        // Add the video source to the scene
        _elements.state.currentScene?.addSource(source);
      }
    });

    const streamDuration = 5;
    print('Dive example: Waiting $streamDuration seconds.');

    Future.delayed(Duration(seconds: streamDuration), () {
      final state = _elements.state;
      // Remove the video and audio sources from the scene
      state.currentScene?.removeAllSceneItems();

      // Remove the video source from the state
      final videoSource = state.videoSources.last;
      // Delete the source resources
      videoSource.dispose();

      // Remove the video source from the state
      final audioSource = state.audioSources.last;
      // Delete the source resources
      audioSource.dispose();

      // Delete the scene resources
      _elements.removeAllScenes();

      _diveCore.shutdown();
    });
  }
}