flutter_to_airplay
flutter_to_airplay copied to clipboard
Video Controls
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),
),
);
}
}
code is not readable
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),
),
);
}
}