Home > Software design >  How to view html live stream on flutter
How to view html live stream on flutter

Time:01-14

I have link: https://g1.ipcamlive.com/player/player.php?alias=theotters&autoplay=1

I do not manage to view this on some Container on Flutter

What I did try:

import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';

void main() {
  runApp(
    const MaterialApp(
      home: MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          height: 300,
          width: 300,
          decoration: BoxDecoration(border: Border.all()),
          child: Html(
            data:
                '<iframe loading="eager" src=https://g1.ipcamlive.com/player/player.php?alias=theotters&autoplay=1"></iframe>',
          ),
        ),
      ),
    );
  }
}

Thanks

CodePudding user response:

Use webview_flutter package instead

https://pub.dev/packages/webview_flutter

I have tested the following code with your url and it works fine.

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late final WebViewController _controller;

  @override
  void initState() {
    _controller = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setBackgroundColor(const Color(0x00000000))
      ..setNavigationDelegate(
        NavigationDelegate(
          onProgress: (int progress) {
            // Update loading bar.
          },
          onPageStarted: (String url) {},
          onPageFinished: (String url) {},
          onWebResourceError: (WebResourceError error) {},
          onNavigationRequest: (NavigationRequest request) {
            return NavigationDecision.navigate;
          },
        ),
      )
      ..loadRequest(Uri.parse('https://g1.ipcamlive.com/player/player.php?alias=theotters&autoplay=1'));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return WebViewWidget(controller: _controller);
  }
}
  • Related