alexmercerind / dart_vlc

Flutter bindings to libVLC.
GNU Lesser General Public License v2.1
509 stars 136 forks source link

Live Streaming URL is crashing the app after a few seconds of play #336

Open Qayoommaymon opened 2 years ago

Qayoommaymon commented 2 years ago

Thanks Hitesh to you & all your team for sharing code of much sought windows flutter library. I would like your kind review/suggestion on an issue faced using the dart_vlc library. I have used the library in Flutter Windows Movies app to show both the network (URL based) movies and the live streaming contents. The dart_vlc player is working fine for the network hosted content however its not working for the live streaming contents. The player crashes while playing the live stream after a few seconds of play.

_Note: The internet connection is working fine for the same contents when played on the web browser & mobile app (using the betterplayer).

The error screens of the player crash are also attached for your review and suggestion. Below is the code snippet used for playing the contents using the dart_vlc:

import 'package:dart_vlc/dart_vlc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_native_view/flutter_native_view.dart';
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';

class DartVLCPlayerWindows extends StatefulWidget {
  final playImage;
  final playURL;
  final title;
  final bool liveStream;
  DartVLCPlayerWindows({
    Key key,
    this.title,
    this.playImage,
    this.playURL,
    this.liveStream,
  }) : super(key: key);

  @override
  DartVLCPlayerWindowsState createState() => DartVLCPlayerWindowsState();
}

class DartVLCPlayerWindowsState extends State<DartVLCPlayerWindows> {
  final controller = NativeViewController(
    /// Using [FindWindow] from `package:win32` to retrieve `HWND` as [int].
    handle: FindWindow(nullptr, 'VLC Media Player'.toNativeUtf16()),
    /// Make the [NativeView] interactable.
    hitTestBehavior: HitTestBehavior.translucent,
  );

  Player videoPlayer = Player(
    id: 7,
    videoDimensions: VideoDimensions(640, 360),
    registerTexture: false
  );

  @override
  void initState() {
    loadVideoPlayer();
    setAudioTrack();
    super.initState();
  }

  loadVideoPlayer() {
    print(widget.playURL);
    videoPlayer.open(
        Media.network(widget.playURL),
        autoStart: true
    );
  }

  void setAudioTrack() async {
    await Future.delayed(const Duration(seconds: 10));
    videoPlayer.setAudioTrack(1);
  }

  @override
  void dispose() {
    videoPlayer.dispose();
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return NativeVideo(
      player: videoPlayer,
      height: double.infinity,
      width: double.infinity,
      fit: BoxFit.contain,
      showControls: true,
      liveStream: widget.liveStream,
    );
  }
}

Screenshots Screenshot 2022-10-13 115328

(below is the Debug screenshot.)

Screenshot 2022-10-13 115737

HAFIZkhan-source commented 1 year ago

App crashing during downloaded video play also

liuchuancong commented 1 year ago

@Qayoommaymon try this!

  bool  playBackisPlaying = false;
desktopController?.playbackStream.listen(desktopStateListener);
      desktopController?.bufferingProgressStream.listen((double  value) {
        if(playBackisPlaying && value != 0.0){
          isPlaying.value = true;
        }else{
          isPlaying.value = false;
        }
      });
 dynamic desktopStateListener(PlaybackState state) {
    playBackisPlaying = state.isPlaying;
  }