red5pro

Red5Pro 流媒体 & 播放器

支持 Red5Pro 流媒体 & 播放器的 Red5Pro 插件。

安装

red5pro 添加到您的 pubspec.yaml

  1. 将以下键值对添加到您应用的 Info.plist(适用于 iOS)

    <plist version="1.0">
    <dict>
        ...
        <key>NSCameraUsageDescription</key>
        <string>Camera Usage</string>
        <key>NSMicrophoneUsageDescription</key>
        <string>Microphone Usage</string>
        <key>NSPhotoLibraryAddUsageDescription</key>
        <string>Photo Usage</string>
        <key>NSPhotoLibraryUsageDescription</key>
        <string>Photo Usage</string>
    </dict>
    </plist>
  2. 将以下 <uses-permissions> 标签添加到您应用的 AndroidManifest.xml(适用于
    Android)

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>
        <uses-permission android:name="android.permission.CAMERA" />
        <uses-permission android:name="android.permission.RECORD_AUDIO" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <application ...>
        ...
  3. 当使用混淆发布 Android 应用时,可能需要以下 Proguard 规则

    -keepattributes *Annotation*,Signature,EnclosingMethod
    -keep class com.red5pro.** { *; }
    -keep interface com.red5pro.** { *; }
    -keep public class com.red5pro.streaming.** { *; }
    -dontwarn com.red5pro.**
    -keep, includedescriptorclasses class com.red5pro.streaming.R5Stream { *; }
    -keep, includedescriptorclasses class com.android.webrtc.audio.** { *; }

在流媒体或播放前请求权限

Future<bool> _hasPermissions() async {
    Map<Permission, PermissionStatus> statuses = await [
      Permission.camera,
      Permission.microphone,
      Permission.storage,
      Permission.phone,
    ].request();
    return statuses.entries
        .where((element) =>
            element.value == PermissionStatus.denied ||
            element.value == PermissionStatus.permanentlyDenied)
        .isEmpty;
  }

用于流媒体

Red5Configuration config = Red5Configuration(
    licenseKey: 'RED5PRO_LICENSE_KEY',
    protocol: R5StreamProtocol.RTSP,
    host: 'YOUR_HOST',
    port: 'HOST_PORT');

late R5StreamViewController r5streamViewController;

Red5StreamView(
    red5configuration: config,
    onR5StreamViewCreated: (controller) {
      r5streamViewController = controller;
    },
  );

// For Start Streaming

r5streamViewController.startStreaming('STREAM_NAME', RecordType.Live);

// For Stop Streaming

r5streamViewController.stopStreaming();

用于流媒体播放器

Red5Configuration config = Red5Configuration(
    licenseKey: 'RED5PRO_LICENSE_KEY',
    protocol: R5StreamProtocol.RTSP,
    host: 'YOUR_HOST',
    port: 'HOST_PORT');

late R5StreamPlayerViewController controller;

Red5StreamPlayerView(
      red5configuration: config,
      streamName: 'STREAM_NAME',
      onR5StreamPlayerViewCreated: (controller) {
        this.controller = controller;
      },
    );

// For Start Playing

controller.play();

// For Stop Playing

controller.stop();

GitHub

查看 Github