Git Product home page Git Product logo

Comments (3)

abdelaziz-mahdy avatar abdelaziz-mahdy commented on June 20, 2024

can you make a reproducible code, and what is the platform you are using? and device?
in general give us as much information as possible so we pinpoint the issue and if its fixable from our end, or wakelock themselves

from media-kit.

Anto-2004 avatar Anto-2004 commented on June 20, 2024

can you make a reproducible code, and what is the platform you are using? and device? in general give us as much information as possible so we pinpoint the issue and if its fixable from our end, or wakelock themselves

This is my code, i have tested on Android, everything works fine but the wakelock doesn't work. As for the device, I use a Samsung s23 for the test.

  ` import 'dart:async';
  
  import 'package:animeTv/models/episode_page.dart';
  import 'package:animeTv/screens/video-player/fullscreen_episodes_screen.dart';
  import 'package:animeTv/util/constants.dart';
  import 'package:animeTv/widgets/custom-player/base_player.dart';
  import "package:flutter/material.dart";
  import 'package:flutter/services.dart';
  import 'package:flutter_spinkit/flutter_spinkit.dart';
  import 'package:media_kit/media_kit.dart';
  import 'package:media_kit_video/media_kit_video.dart';
  
  class CustomPlayer extends StatefulWidget {
    final GlobalKey<VideoState> videoKey;
    final VideoController controller;
    final bool fromDownload;
    final EpisodePage? episode;
    final Function callback;
    final int initialPosition;
    final VoidCallback nextEpisode;
    final Function(String episodeLink) startEpisode;
    final List<EpisodeInList>? episodes;
  
    const CustomPlayer({
      super.key,
      required this.videoKey,
      required this.controller,
      required this.fromDownload,
      required this.episode,
      required this.callback,
      required this.initialPosition,
      required this.nextEpisode,
      required this.startEpisode,
      this.episodes,
    });
  
    @override
    State<CustomPlayer> createState() => _CustomPlayerState();
  }
  
  class _CustomPlayerState extends State<CustomPlayer> {
    bool hasLoaded = false;
    bool hasError = false;
  
    void initController() {
      if (!widget.fromDownload) {
        widget.controller.player.stream.position.listen(
          (Duration position) {
            widget.callback(position);
          },
        );
      }
    }
  
    void loadVideo(Duration position, String url) async {
      await widget.controller.player.open(Media(url));
      widget.controller.player.stream.duration.listen((event) async {
        if (event.inSeconds > 0) {
          await widget.controller.player.seek(position);
        }
      });
    }
  
    void _moveSeconds(String moveType) async {
      final currentDuration = widget.controller.player.state.position;
      //aggiungo o sottraggo 10 secondi alla durata iniziale
      final newDuration =
          currentDuration + Duration(seconds: moveType == "forward" ? 10 : -10);
  
      await widget.controller.player.seek(newDuration);
    }
  
    void _onClosePlayer() {
      //se sono nei download  chiudo la pagina completamente e torno a quella precedente
      if (widget.fromDownload) {
        Navigator.of(context).popUntil((route) => route.isFirst);
      } else {
        Constants.navigatorKey.currentState?.pop();
      }
  
      SystemChrome.setPreferredOrientations([
        DeviceOrientation.portraitUp,
        DeviceOrientation.portraitDown,
      ]);
  
      SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.top, SystemUiOverlay.bottom]);
    }
  
    void _openEpisodes() {
      widget.controller.player.pause();
      Constants.navigatorKey.currentState!
          .push(MaterialPageRoute(builder: (context) {
        return FullscreenEpisodesScreen(
          allEpisodes: widget.episodes!,
          startEpisode: (String episodeLink) {
            widget.startEpisode(episodeLink);
          },
          onClose: () {
            widget.controller.player.play();
          },
        );
      }));
    }
  
    Future<void> initPlayer({
      required Duration position,
    }) async {
      loadVideo(position, widget.episode!.videoUrl);
    }
  
    initAll() async {
      initController();
      initPlayer(position: Duration(seconds: widget.initialPosition));
  
      setState(() {
        hasLoaded = true;
      });
    }
  
    @override
    void initState() {
      initAll();
      super.initState();
    }
  
    @override
    Widget build(BuildContext context) {
      return BasePlayer(
        controller: widget.controller,
        nextEpisode: widget.nextEpisode,
        moveSeconds: (String type) {
          _moveSeconds(type);
        },
        onClosePlayer: () {
          _onClosePlayer();
        },
        openEpisodes: widget.episodes != null ? _openEpisodes : null,
        fromDownload: widget.fromDownload,
        body: hasError
            ? Container(
                alignment: Alignment.center,
                color: Theme.of(context).colorScheme.background,
                child: const Text(
                  "Sembra che il video sia ancora in fase di elaborazione,\n riprova più tardi",
                  textAlign: TextAlign.center,
                ),
              )
            : hasLoaded
                ? Video(
                    key: widget.videoKey,
                    controller: widget.controller,
                    controls: MaterialVideoControls,
                    onEnterFullscreen: () async {
                      await defaultEnterNativeFullscreen();
                    },
                    onExitFullscreen: () async {
                      _onClosePlayer();
                    },
                  )
                : Flexible(
                    child: Center(
                      child: SpinKitThreeInOut(
                        color: Theme.of(context).colorScheme.primary,
                        size: 30,
                      ),
                    ),
                  ),
      );
    }
  }`

from media-kit.

abdelaziz-mahdy avatar abdelaziz-mahdy commented on June 20, 2024

Please give a test code with the problem that I can run,

Better question what are you testing on and does the problem happen on the example app? If not then it's a problem on your side check that you don't disable wake lock by mistake

from media-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.