Open tuyenkim opened 2 years ago
please go throw the below code. i hope this will help you. after a lot of experiment finally got success in zooming. now working on automatic scaling on landscape mode.
import 'dart:io';
import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart'; import 'package:sglive/model/VideoModel.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'dart:async'; //import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:sglive/Utils/Utility.dart'; import 'package:flutter_vlc_player/flutter_vlc_player.dart'; import 'package:youtube_player_flutter/youtube_player_flutter.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
class Player extends StatefulWidget { final Result? result; const Player({Key? key, @required this.result}) : super(key: key);
@override _PlayerState createState() => _PlayerState(); }
class _PlayerState extends State
initVideo() async {
String url1 = Uri.parse(widget.result!.url).toString();
_vlcPlayerController = VlcPlayerController.network(
url1,
autoPlay: true,
autoInitialize: true,
options: VlcPlayerOptions(),
hwAcc: HwAcc.full,
);
_vlcPlayerController.addListener(() {
if (_vlcPlayerController.value.position ==
_vlcPlayerController.value.duration) {
print('video Ended');
}
});
}
@override void initState() { super.initState(); initVideo();
Future.delayed(Duration(seconds: 2), () { // <-- Delay here
setState(() {
isPlaying = false; // <-- Code run after delay
});
});
}
@override void dispose() { super.dispose(); print('dipose'); _vlcPlayerController.dispose();
// _chewieController.dispose();
}
@override Widget build(BuildContext context) {
// final double scale = 3; // final zoomed = Matrix4.identity()..scale(scale); //final value = zoomed; //fit: BoxFit.cover,
double screenwidth = (MediaQuery.of(context).size.width);
double screenheight = (MediaQuery.of(context).size.height);
return Dismissible(
direction: DismissDirection.vertical,
key: const Key('key'),
onDismissed: (_) => Navigator.of(context).pop(),
child: InteractiveViewer(
panEnabled: false, // Set it to false to prevent panning.
boundaryMargin: EdgeInsets.all(80),
minScale: 0.5,
maxScale: 4,
child: Scaffold(
appBar: AppBar(),
body: Container(
alignment: Alignment.center,
margin: EdgeInsets.all(10),
height: screenheight,
width: screenwidth,
child: Stack(
children: <Widget>[
if (isPlaying == true) ...[
Center(child: CircularProgressIndicator()),
] else ...[
VlcPlayer(
controller: _vlcPlayerController,
aspectRatio: 16 / 9,
),
],
Row(
children: [
IconButton(
onPressed: (){
if(MediaQuery.of(context).orientation == Orientation.portrait){
//if Orientation is portrait then set to landscape mode
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}else{
//if Orientation is landscape then set to portrait
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitDown,
DeviceOrientation.portraitUp,
]);
}
}, icon: Icon(Icons.screen_rotation, color: Colors.white,),
),
],
),
],
),
),
)
),
);
} }
@vishnu7567 thank you for the answer. I try with your sample code , it can pinch to zoom but size of widget is changed, I want to zoom not change size of widget. Can you help me zoom with below source code (sample code of flutter_vlc_player plugin) https://pub.dev/packages/flutter_vlc_player/versions
Yea same. It pauses the video on scale. After scale > 2.0. But still okay when < 2.0. Got log: I/ViewRootImpl@345b67MainActivity: ViewPostIme pointer 0 I/ViewRootImpl@345b67MainActivity: ViewPostIme pointer 1
every pinch when the video paused by the scale. Any solution?
I use InteractiveViewer to pinch to zoom with flutter_vlc_player but it not working properly. I do hope you will help me solve the problem. InteractiveViewer( transformationController: _transformationController , child: VlcPlayer( controller: controller, aspectRatio: 16 / 9, ), panEnabled: true, scaleEnabled: true, minScale: 1.0, maxScale: 4, )