Created
July 25, 2022 20:44
-
-
Save irvine5k/c2b2e668af8a4694dfff5bb27d84a85f to your computer and use it in GitHub Desktop.
main.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:video_360/video_360.dart'; | |
void main() { | |
WidgetsFlutterBinding.ensureInitialized(); | |
runApp(MaterialApp(home: Home())); | |
} | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
late Video360Controller controller; | |
String durationText = ''; | |
String totalText = ''; | |
@override | |
void initState() { | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
var statusBar = MediaQuery.of(context).padding.top; | |
var width = MediaQuery.of(context).size.width; | |
var height = MediaQuery.of(context).size.height; | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Video 360 Plugin example app'), | |
), | |
body: Stack( | |
children: [ | |
Center( | |
child: Container( | |
width: width, | |
height: height, | |
child: Video360View( | |
onVideo360ViewCreated: _onVideo360ViewCreated, | |
url: | |
'https://bitmovin-a.akamaihd.net/content/playhouse-vr/m3u8s/105560.m3u8', | |
onPlayInfo: (Video360PlayInfo info) { | |
setState(() { | |
durationText = info.duration.toString(); | |
totalText = info.total.toString(); | |
}); | |
}, | |
), | |
), | |
), | |
Column( | |
children: [ | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
MaterialButton( | |
onPressed: () { | |
controller.play(); | |
}, | |
color: Colors.grey[100], | |
child: Text('Play'), | |
), | |
MaterialButton( | |
onPressed: () { | |
controller.stop(); | |
}, | |
color: Colors.grey[100], | |
child: Text('Stop'), | |
), | |
MaterialButton( | |
onPressed: () { | |
controller.reset(); | |
}, | |
color: Colors.grey[100], | |
child: Text('Reset'), | |
), | |
MaterialButton( | |
onPressed: () { | |
controller.jumpTo(80000); | |
}, | |
color: Colors.grey[100], | |
child: Text('1:20'), | |
), | |
], | |
), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
MaterialButton( | |
onPressed: () { | |
controller.seekTo(-2000); | |
}, | |
color: Colors.grey[100], | |
child: Text('<<'), | |
), | |
MaterialButton( | |
onPressed: () { | |
controller.seekTo(2000); | |
}, | |
color: Colors.grey[100], | |
child: Text('>>'), | |
), | |
Flexible( | |
child: MaterialButton( | |
onPressed: () {}, | |
color: Colors.grey[100], | |
child: Text(durationText + ' / ' + totalText), | |
), | |
), | |
], | |
) | |
], | |
) | |
], | |
), | |
); | |
} | |
_onVideo360ViewCreated(Video360Controller controller) { | |
this.controller = controller; | |
} | |
} | |
class Home extends StatelessWidget { | |
const Home({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Player'), | |
), | |
body: Center( | |
child: ElevatedButton( | |
child: Text('Go to 360º video'), | |
onPressed: () { | |
Navigator.push( | |
context, MaterialPageRoute(builder: (context) => MyApp())); | |
}, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment