如何在颤振中播放 rtsp 视频流?

Posted

技术标签:

【中文标题】如何在颤振中播放 rtsp 视频流?【英文标题】:how can i play rtsp video stream in flutter? 【发布时间】:2021-08-16 18:56:28 【问题描述】:

这是我正在尝试使用 flutter vlc player 的代码,但它不起作用,所以任何人都可以帮助我解决问题,或者我可以用另一种方式显示流?

所以你们可以给我任何建议或举任何小例子。我试图从过去两个小时解决这个问题,但它没有解决

import 'package:flutter/material.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
import 'package:flutter_vlc_player/vlc_player.dart';
import 'package:flutter_vlc_player/vlc_player_controller.dart';
void main() 
  runApp(MyApp());


class MyApp extends StatelessWidget 
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) 
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
    );
  


class MyHomePage extends StatefulWidget 
  MyHomePage(Key key) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();


class _MyHomePageState extends State<MyHomePage> 
  VlcPlayerController _videoPlayerController;

  @override
  void initState() 
    super.initState();

    _videoPlayerController = VlcPlayerController.network(
      'rtsp://viewer:aeDoPhiucees3gohshie@173.249.14.110:27954/axis-media/media.amp?videocodec=h264&fps=15&audio=1&resolution=640x480',
      hwAcc: HwAcc.FULL,
      autoPlay: false,
      options: VlcPlayerOptions(),
    );
  

  @override
  void dispose() async 
    super.dispose();
    await _videoPlayerController.stopRendererScanning();
    await _videoPlayerController.dispose();
  

  @override
  Widget build(BuildContext context) 
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: VlcPlayer(
          controller: _videoPlayerController,
          aspectRatio: 16 / 9,
          placeholder: Center(child: CircularProgressIndicator()),
        ),
      ),
    );
  

【问题讨论】:

【参考方案1】:

这是一个对我有用的小例子。我认为问题是在较新的版本中必须立即初始化控制器。

我对这段代码的唯一问题是高级选项不起作用。不幸的是,很难找到一些好的信息

import 'package:flutter/material.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
import 'package:flutter_vlc_player/src/vlc_player_controller.dart';

void main() 
  runApp(MyApp());


class MyApp extends StatelessWidget 
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) 
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  


class MyHomePage extends StatefulWidget 
  MyHomePage(Key? key, required this.title) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();


class _MyHomePageState extends State<MyHomePage> 
  VlcPlayerController _vlcViewController = new VlcPlayerController.network(
    "rtsp://192.72.1.1/liveRTSP/av4",
    autoPlay: true,
  );

  @override
  Widget build(BuildContext context) 
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new VlcPlayer(
              controller: _vlcViewController,
              aspectRatio: 16 / 9,
              placeholder: Text("Hello World"),
            ),
          ],
        ),
      ),
    );
  

【讨论】:

感谢您提供有关立即初始化控制器的提示。这解决了我的问题!【参考方案2】:

查看这个库:https://pub.dev/packages/flutter_playout。它确实支持 HLS。

【讨论】:

以上是关于如何在颤振中播放 rtsp 视频流?的主要内容,如果未能解决你的问题,请参考以下文章

如何在颤振中播放来自vimeo的私人视频

如何将 RTSP 视频 url 播放到 EXOPlayer

EasyNVR如何获取RTSP格式的视频流?三种获取RTSP地址方式介绍

网页无插件视频流媒体播放器EasyPlayer-RTSP在WPF框架播放不显示视频画面,该如何排查处理?

记:rtmp,rtsp,http视频流播放

在web端实现rtsp流的视频的播放