newtaDev / pod_player

Video player for flutter web & mobile devices, Play video from youtube or vimeo or network in flutter using pod player
https://pub.dev/packages/pod_player
MIT License
105 stars 201 forks source link

exit Fullscreen #88

Open adrianofreires opened 1 year ago

adrianofreires commented 1 year ago

Hi! I have a strange bug!

I've set the page to always be in portrait position. When I enable the video in fullscreen mode it goes to a new page with the video in fullscreen in the landscape position, so far so good! The problem is when I exit the fullscreen mode and go back to the previous screen. The page is no longer set in portrait mode, it follows the orientation of the cell phone. When I go back once more and now I go to the home screen which is also set in portrait mode and I go to the screen where the video is, it goes back to being set in portrait mode.

Follow the code:

`import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:hive/hive.dart'; import 'package:provider/provider.dart'; import 'package:share_plus/share_plus.dart';

import '../blocs/blocs.dart'; import '../config/config.dart'; import '../models/models.dart'; import '../services/services.dart'; import '../widgets/widgets.dart';

class VideoArticleDetails extends StatefulWidget { final Article article; const VideoArticleDetails({Key? key, required this.article}) : super(key: key);

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

class _VideoArticleDetailsState extends State { double _rightPaddingValue = 100; var scaffoldKey = GlobalKey();

Future _handleShare() async { Share.share(widget.article.link!); }

@override void initState() { super.initState(); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); Future.delayed(const Duration(milliseconds: 0)).then((value) => context.read().showLoadedAds()); Future.delayed(const Duration(milliseconds: 100)).then((value) => setState(() { _rightPaddingValue = 10; })); }

@override void dispose() { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); super.dispose(); }

@override Widget build(BuildContext context) { final bookmarkedList = Hive.box(Constants.bookmarkTag); return Scaffold( backgroundColor: Theme.of(context).backgroundColor, key: scaffoldKey, appBar: _appBar(), body: SafeArea( bottom: true, child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ VideoPlayerPod(videoUrl: widget.article.video!, videoType: 'youtube'), Expanded( flex: 1, child: SingleChildScrollView( child: Column( children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.fromLTRB(20, 20, 20, 0), child: Column( children: [ Row( children: [ Container( alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.circular(5), color: Theme.of(context).colorScheme.onBackground, ), child: AnimatedPadding( duration: const Duration(milliseconds: 500), padding: EdgeInsets.only(left: _rightPaddingValue, right: _rightPaddingValue, top: 5, bottom: 5), child: Text( widget.article.category!, style: TextStyle(fontSize: 15, color: Theme.of(context).colorScheme.primary, fontWeight: FontWeight.w600), ), ), ), const Spacer(), BookmarkIcon( bookmarkedList: bookmarkedList, article: widget.article, iconSize: 22, iconColor: Colors.blueGrey, normalIconColor: Colors.grey, ), ], ), ], ), ), const SizedBox( height: 15, ), Padding( padding: const EdgeInsets.only(left: 20, bottom: 12), child: Row( children: [ const SizedBox( width: 5, ), Text( widget.article.timeAgo!, style: TextStyle( fontSize: 14, color: Theme.of(context).colorScheme.secondary, ), ), ], ), ), const SizedBox( width: 15, ), const SizedBox( width: 10, ), Padding( padding: const EdgeInsets.only(left: 20.0), child: Text( AppService.getNormalText(widget.article.title!), style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, letterSpacing: -0.6, wordSpacing: 1), ), ), Padding( padding: const EdgeInsets.only(left: 20.0), child: Divider( color: Theme.of(context).primaryColor, endIndent: 280, thickness: 2, ), ), const SizedBox( height: 5, ), HtmlBody(content: widget.article.content!, isVideoEnabled: false, isImageEnabled: true, isIframeVideoEnabled: true), const SizedBox( height: 20, ), ], ), RelatedArticles(postId: widget.article.id, catId: widget.article.catId), const SizedBox( height: 50, ), ], ), ), ), AdsConfig.isAdsEnabled == true ? const BannerAdsWidget() : Container(), ], ), ), ); //}); }

AppBar _appBar() { return AppBar( automaticallyImplyLeading: false, toolbarHeight: 45, leading: IconButton( onPressed: () => Navigator.pop(context), icon: const Icon( Icons.arrow_back_ios_sharp, size: 20, ), ), actions: [ Padding( padding: const EdgeInsets.only(right: 6.0), child: IconButton( onPressed: () => _handleShare(), icon: const Icon( Icons.share, size: 20, ), ), ), ], ); } } `

`import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:pod_player/pod_player.dart';

class VideoPlayerPod extends StatefulWidget { final String videoUrl; final String videoType; final String? thumbnailUrl; const VideoPlayerPod({Key? key, required this.videoUrl, required this.videoType, this.thumbnailUrl}) : super(key: key);

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

class _VideoPlayerWidgetState extends State { late final PodPlayerController controller;

@override void initState() { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); controller = PodPlayerController( playVideoFrom: widget.videoType == 'network' ? PlayVideoFrom.network(widget.videoUrl) : widget.videoType == 'vimeo' ? PlayVideoFrom.vimeo(widget.videoUrl) : PlayVideoFrom.youtube(widget.videoUrl), podPlayerConfig: const PodPlayerConfig( autoPlay: false, isLooping: false, )) ..initialise(); super.initState(); }

@override void dispose() { controller.dispose(); SystemChrome.setPreferredOrientations(DeviceOrientation.values); super.dispose(); }

@override Widget build(BuildContext context) { return PodVideoPlayer( controller: controller, alwaysShowProgressBar: true, videoThumbnail: widget.thumbnailUrl == null ? null : DecorationImage(fit: BoxFit.cover, image: CachedNetworkImageProvider(widget.thumbnailUrl!)), ); } }`

skynetto commented 1 year ago

comment line 192 on pod_video_controller.dart