gpt4 book ai didi

video - Flutter 直播

转载 作者:IT老高 更新时间:2023-10-28 12:42:11 30 4
gpt4 key购买 nike

我正在尝试构建一个移动应用程序,该应用程序从设备的摄像头流式传输视频并将其实时发送到服务器。此外,移动设备应该能够播放从服务器接收到的实况视频。

我正在 Flutter 中构建应用程序,但似乎无法在 Flutter 中找到使用 HLS/RTSL/WebRTC/等的有据可查的库/包。

我应该使用字节流并制作自定义解决方案,还是我可以使用官方包来完成这项工作?

提前感谢您!

最佳答案

对于 WebRTC 请尝试这个包 flutter_webrtc
https://github.com/cloudwebrtc/flutter-webrtc
以及更多示例链接
https://github.com/cloudwebrtc/flutter-webrtc-demo/

import 'package:flutter/material.dart';
import 'package:flutter_webrtc/webrtc.dart';
import 'dart:core';

/**
* getUserMedia sample
*/
class GetUserMediaSample extends StatefulWidget {
static String tag = 'get_usermedia_sample';

@override
_GetUserMediaSampleState createState() => new _GetUserMediaSampleState();
}

class _GetUserMediaSampleState extends State<GetUserMediaSample> {
MediaStream _localStream;
final _localRenderer = new RTCVideoRenderer();
bool _inCalling = false;

@override
initState() {
super.initState();
initRenderers();
}

@override
deactivate() {
super.deactivate();
if (_inCalling) {
_hangUp();
}
}

initRenderers() async {
await _localRenderer.initialize();
}

// Platform messages are asynchronous, so we initialize in an async method.
_makeCall() async {
final Map<String, dynamic> mediaConstraints = {
"audio": true,
"video": {
"mandatory": {
"minWidth":'640', // Provide your own width, height and frame rate here
"minHeight": '480',
"minFrameRate": '30',
},
"facingMode": "user",
"optional": [],
}
};

try {
var stream = await navigator.getUserMedia(mediaConstraints);
_localStream = stream;
_localRenderer.srcObject = _localStream;
} catch (e) {
print(e.toString());
}
if (!mounted) return;

setState(() {
_inCalling = true;
});
}

_hangUp() async {
try {
await _localStream.dispose();
_localRenderer.srcObject = null;
} catch (e) {
print(e.toString());
}
setState(() {
_inCalling = false;
});
}

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('GetUserMedia API Test'),
),
body: new OrientationBuilder(
builder: (context, orientation) {
return new Center(
child: new Container(
margin: new EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: RTCVideoView(_localRenderer),
decoration: new BoxDecoration(color: Colors.black54),
),
);
},
),
floatingActionButton: new FloatingActionButton(
onPressed: _inCalling ? _hangUp : _makeCall,
tooltip: _inCalling ? 'Hangup' : 'Call',
child: new Icon(_inCalling ? Icons.call_end : Icons.phone),
),
);
}
}

关于video - Flutter 直播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54988284/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com