video_player_win 2.3.9 copy "video_player_win: ^2.3.9" to clipboard
video_player_win: ^2.3.9 copied to clipboard

Video player for Windows, lightweight, using Windows built-in Media Foundation API. Windows implementation of the video_player plugin.

example/lib/main.dart

import 'dart:async';
import 'dart:io';

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

void main() {
  runApp(const MyApp());
}

const gFileList = [
  "E:\\test_align.mp4",
  "E:\\test_youtube.mp4",
];

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

  @override
  State createState() => _MyAppState();
}

class _MyAppState extends State {
  PHFPlayerVideoPlayer player1 = PHFPlayerVideoPlayer();
  PHFPlayerVideoPlayer player2 = PHFPlayerVideoPlayer();
  late PHFPlayerVideoPlayer currentPlayer;
  bool showPlayer = false;
  int nowIndex = 0;

  @override
  initState() {
    super.initState();
    nowIndex = 0;
    Future.delayed(Duration(seconds: 1), () async {
      await player1.initializeVideoSlide(gFileList[0]);
      player1.index = 1;
      int nextIndex = (nowIndex + 1) % gFileList.length; // loop the list
      await player2.initializeVideoSlide(gFileList[1]);
      player2.index = 2;
      currentPlayer = player1;

      Timer.periodic(Duration(seconds: 5), (Timer) async {
        await switchPlayer();
      });
      setState(() {
        showPlayer = true;
      });
    });
  }

  switchPlayer() async {
    if (currentPlayer.index == 1) {
      currentPlayer = player2;
      await player1.videoPlayerController!.dispose();
      await player1.initializeVideoSlide(gFileList[0]);
    } else {
      currentPlayer = player1;
      await player2.videoPlayerController!.dispose();
      await player2.initializeVideoSlide(gFileList[1]);
    }

    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Stack(children: [
          showPlayer ? currentPlayer.getVideoWidget(false) : Container()
        ]),
      ),
    );
  }
}

class PHFPlayerVideoPlayer {
  int index = 0;
  WinVideoPlayerController? videoPlayerController;

  initializeVideoSlide(videoFile) async {
    videoPlayerController = WinVideoPlayerController.file(File(videoFile));
    await videoPlayerController!.initialize();
  }

  Widget getVideoWidget(useBlur) {
    videoPlayerController!.play();
    return WinVideoPlayer(videoPlayerController!);
  }
}
54
likes
0
points
7.4k
downloads

Publisher

unverified uploader

Weekly Downloads

Video player for Windows, lightweight, using Windows built-in Media Foundation API. Windows implementation of the video_player plugin.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface, video_player_platform_interface

More

Packages that depend on video_player_win