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

PlatformWindows

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:developer';
import 'dart:io';

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

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

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

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

class _MyAppState extends State<MyApp> {
  WinVideoPlayerController? controller;

  void reload() {
    controller?.dispose();
    //controller = WinVideoPlayerController.file(File("D:\\test\\test_youtube.mp4"));
    //controller = WinVideoPlayerController.file(File("D:\\test\\test_youtube_1.mp4"));
    controller = WinVideoPlayerController.file(File("D:\\test\\test_4k.mp4"));
    //controller = WinVideoPlayerController.file(File("D:\\test\\test_hapM.mov"));
    //controller = WinVideoPlayerController.network("https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.ism/.m3u8");
    //controller = WinVideoPlayerController.file(File("D:\\test\\test_av1.mp4"));
    //controller = WinVideoPlayerController.file(File("D:\\test\\test_av1_no_audio.mp4"));
    //controller = WinVideoPlayerController.file(File("D:\\test\\test_audio.mp3"));
    //controller = WinVideoPlayerController.file(File("D:\\test\\test_youtub_δΈ­ζ–‡.mp4"));
    //controller = WinVideoPlayerController.file(File("D:\\----------load-fail-test"));
    //controller = VideoPlayerController.networkUrl(Uri.parse("https://media.w3.org/2010/05/sintel/trailer.mp4"));
    //controller = WinVideoPlayerController.file(File("E:\\Downloads\\0.FDM\\sample-file-1.flac"));

    controller!.initialize().then((value) {
      if (controller!.value.isInitialized) {
        controller!.play();
        controller!.setLooping(true);
        setState(() {});

        controller!.addListener(() {
          if (controller!.value.isCompleted) {
            log("ui: player completed, pos=${controller!.value.position}");
          }
        });
      } else {
        log("video file load failed");
      }
    }).catchError((e) {
      log("controller.initialize() error occurs: $e");
    });
    setState(() {});
  }

  @override
  void initState() {
    super.initState();
    reload();
  }

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('video_player_win example app'),
        ),
        body: Stack(children: [
          Container(
            color: Colors.black,
            child: WinVideoPlayer(controller!),
          ),
          Positioned(
              bottom: 0,
              child: Column(children: [
                ValueListenableBuilder<WinVideoPlayerValue>(
                  valueListenable: controller!,
                  builder: ((context, value, child) {
                    int minute = value.position.inMinutes;
                    int second = value.position.inSeconds % 60;
                    String timeStr = "$minute:$second";
                    if (value.isCompleted) timeStr = "$timeStr (completed)";
                    return Text(timeStr,
                        style: Theme.of(context)
                            .textTheme
                            .headlineMedium!
                            .copyWith(
                                color: Colors.white,
                                backgroundColor: Colors.black54));
                  }),
                ),
                ElevatedButton(
                    onPressed: () => reload(),
                    //onPressed: () => controller?.dispose(),
                    child: const Text("Reload")),
                ElevatedButton(
                    onPressed: () => controller?.play(),
                    child: const Text("Play")),
                ElevatedButton(
                    onPressed: () => controller?.pause(),
                    child: const Text("Pause")),
                ElevatedButton(
                    onPressed: () => controller?.seekTo(Duration(
                        milliseconds:
                            controller!.value.position.inMilliseconds +
                                10 * 1000)),
                    child: const Text("Forward")),
                ElevatedButton(
                    onPressed: () {
                      int ms = controller!.value.duration.inMilliseconds;
                      var tt = Duration(milliseconds: ms - 1000);
                      controller?.seekTo(tt);
                    },
                    child: const Text("End")),
              ])),
        ]),
      ),
    );
  }
}
54
likes
140
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

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface, video_player_platform_interface

More

Packages that depend on video_player_win