Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video Controls #21

Open
xTheMasters opened this issue Nov 1, 2022 · 2 comments
Open

Video Controls #21

xTheMasters opened this issue Nov 1, 2022 · 2 comments

Comments

@xTheMasters
Copy link

xTheMasters commented Nov 1, 2022

Hello I use this amazing plugin but I got some error and with the controllers sometime dont work for play, forward or fullscreen

here is my code i testing in a simulator and a real device

import 'package:flutter/material.dart';

import 'dart:io' show Platform;
import 'package:appinio_video_player/appinio_video_player.dart';
import 'package:flutter/services.dart';

import '../../../global_widgets/video_player_airplay/flutter_to_airplay.dart';

class ExercisePageView extends StatefulWidget {
  final String? video;
  final String? title;
  final String? id;
  final String? time;
  final String? rep;
  final VoidCallback? onRewindVideo;
  final VoidCallback? onNextVideo;
  final VideoPlayerController? controller;
  const ExercisePageView({
    Key? key,
    this.video,
    this.id,
    this.time,
    this.rep,
    this.title,
    this.controller,
    this.onRewindVideo,
    this.onNextVideo,
  }) : super(key: key);

  @override
  State<ExercisePageView> createState() => _ExercisePageViewState();
}

class _ExercisePageViewState extends State<ExercisePageView> {
  ChewieController? _chewieController;
  VideoPlayerController? _videoPlayerController;
  // CustomVideoPlayerController _customVideoPlayerController;
  final controller = PageController();
  String _platformVersion = 'Unknown';
  @override
  void initState() {
    super.initState();
    _videoPlayerController = VideoPlayerController.network(widget.video!);
    if (Platform.isIOS) {
      initPlatformState();
    } else if (Platform.isAndroid) {
      _videoPlayerController!.initialize().then((_) {
        _chewieController = ChewieController(
            allowPlaybackSpeedChanging: false,
            autoPlay: true,
            looping: true,
            allowMuting: false,
            videoPlayerController: _videoPlayerController!);
        setState(() {});
      });
    }
  }

  Future<void> initPlatformState() async {
    String platformVersion;

    try {
      platformVersion = await FlutterToAirplay.platformVersion;
    } on PlatformException {
      platformVersion = 'Faileds to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  void dispose() {
    super.dispose();

    if (Platform.isIOS) {
      // initPlatformState();
    } else if (Platform.isAndroid) {
      _videoPlayerController!.dispose();
      _chewieController!.dispose();
    }
  }

  @override
  Widget build(BuildContext context) {
    if (Platform.isIOS) {
      return Scaffold(
        backgroundColor: Colors.black,
        body: SafeArea(
          child: Center(
            child: FlutterAVPlayerView(
              urlString: widget.video,
            ),
          ),
        ),
      );
    } else if (Platform.isAndroid) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        home: Scaffold(
            backgroundColor: Colors.black,
            body: _videoPlayerController != null
                ? Center(
                    child: _videoPlayerController!.value.isInitialized
                        ? Container(
                            color: Colors.black,
                            child: Chewie(controller: _chewieController!))
                        : const Center(child: CircularProgressIndicator()))
                : const Center(child: CircularProgressIndicator())),
      );
    }
    return Center(
      child: Text(
        _platformVersion,
        style: const TextStyle(color: Colors.transparent),
      ),
    );
  }
}

@ViktorKirjanov
Copy link

code is not readable

@xTheMasters
Copy link
Author

code is not readable

import 'package:flutter/material.dart';

import 'dart:io' show Platform;
import 'package:appinio_video_player/appinio_video_player.dart';
import 'package:flutter/services.dart';

import '../../../global_widgets/video_player_airplay/flutter_to_airplay.dart';

class ExercisePageView extends StatefulWidget {
  final String? video;
  final String? title;
  final String? id;
  final String? time;
  final String? rep;
  final VoidCallback? onRewindVideo;
  final VoidCallback? onNextVideo;
  final VideoPlayerController? controller;
  const ExercisePageView({
    Key? key,
    this.video,
    this.id,
    this.time,
    this.rep,
    this.title,
    this.controller,
    this.onRewindVideo,
    this.onNextVideo,
  }) : super(key: key);

  @override
  State<ExercisePageView> createState() => _ExercisePageViewState();
}

class _ExercisePageViewState extends State<ExercisePageView> {
  ChewieController? _chewieController;
  VideoPlayerController? _videoPlayerController;
  // CustomVideoPlayerController _customVideoPlayerController;
  final controller = PageController();
  String _platformVersion = 'Unknown';
  @override
  void initState() {
    super.initState();
    _videoPlayerController = VideoPlayerController.network(widget.video!);
    if (Platform.isIOS) {
      initPlatformState();
    } else if (Platform.isAndroid) {
      _videoPlayerController!.initialize().then((_) {
        _chewieController = ChewieController(
            allowPlaybackSpeedChanging: false,
            autoPlay: true,
            looping: true,
            allowMuting: false,
            videoPlayerController: _videoPlayerController!);
        setState(() {});
      });
    }
  }

  Future<void> initPlatformState() async {
    String platformVersion;

    try {
      platformVersion = await FlutterToAirplay.platformVersion;
    } on PlatformException {
      platformVersion = 'Faileds to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  void dispose() {
    super.dispose();

    if (Platform.isIOS) {
      // initPlatformState();
    } else if (Platform.isAndroid) {
      _videoPlayerController!.dispose();
      _chewieController!.dispose();
    }
  }

  @override
  Widget build(BuildContext context) {
    if (Platform.isIOS) {
      return Scaffold(
        backgroundColor: Colors.black,
        body: SafeArea(
          child: Center(
            child: FlutterAVPlayerView(
              urlString: widget.video,
            ),
          ),
        ),
      );
    } else if (Platform.isAndroid) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        home: Scaffold(
            backgroundColor: Colors.black,
            body: _videoPlayerController != null
                ? Center(
                    child: _videoPlayerController!.value.isInitialized
                        ? Container(
                            color: Colors.black,
                            child: Chewie(controller: _chewieController!))
                        : const Center(child: CircularProgressIndicator()))
                : const Center(child: CircularProgressIndicator())),
      );
    }
    return Center(
      child: Text(
        _platformVersion,
        style: const TextStyle(color: Colors.transparent),
      ),
    );
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants