how can i play rtsp video stream in flutter?
Here is a small example that works for me. I think the problem is that in the newer versions the Controller must be initialized immediately.
The only problems I have with this code is that the advanced options take no effect. Unfortunately it is hard to find some good information
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"),
),
],
),
),
);
}
}
Muhammad Arbaz Zafar
I software engineer graduated from superior university Lahore . My main focus to developing the cross platform application by using flutter i m also blockchain expert. I m looking for great opportunity and want to work on big projects.
Updated on December 30, 2022Comments
-
Muhammad Arbaz Zafar over 1 year
this is my code thats i m trying by using
flutter vlc player
but its not working so any can help me to solving the issue or i can show stream with another way?so you guys can give me any suggestion or give any little example. i m trying to solve this issue from last two hours but its not going
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:[email protected]: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()), ), ), ); } }
-
E.Bradford over 2 yearsThank you for the tip about initializing the controller immediately. That solved my problem!