I want to use flutter video_player, it plays videos in emulator, but not able to play H.264 mp4 videos in most of real android device, anyone know the solution?
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:newflutter/views/authscreens/login.dart';
import 'package:video_player/video_player.dart';
class LocalVideoStoryItem extends StatefulWidget {
final String videoPath;
final Duration duration;
final Widget? caption;
const LocalVideoStoryItem({
required this.videoPath,
required this.duration,
this.caption,
Key? key,
}) : super(key: key);
@override
_LocalVideoStoryItemState createState() => _LocalVideoStoryItemState();
}
class _LocalVideoStoryItemState extends State<LocalVideoStoryItem> {
late VideoPlayerController _controller;
late Future<void> _initializeVideoPlayerFuture;
GetStorage localMemory = GetStorage();
@override
void initState() {
super.initState();
_controller = VideoPlayerController.asset(widget.videoPath);
_initializeVideoPlayerFuture = _controller.initialize().then((_) {
setState(() {
_controller.play();
});
});
_controller.setLooping(true);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.center,
children: [
FutureBuilder(
future: _initializeVideoPlayerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
);
} else {
return const Center(child: CircularProgressIndicator());
}
},
),
if (widget.caption != null)
Positioned(
bottom: 10,
left: 10,
right: 10,
child: widget.caption!,
),
if (widget.caption == null)
Positioned(
bottom: 10,
left: 10,
right: 10,
child: Column(
children: [
Container(
color: Colors.transparent,
padding: const EdgeInsets.all(18.0),
child: const Text(
"Explore ",
style: TextStyle(
backgroundColor: Colors.transparent,
decoration: TextDecoration.none,
color: Color(0xFF10489B),
fontSize: 22,
fontWeight: FontWeight.w600,
),
textAlign: TextAlign.center,
),
),
Container(
width: double.infinity,
height: 50,
padding: const EdgeInsets.symmetric(horizontal: 20),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xff00BAE4),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
),
onPressed: () {
Get.offAll(() => const Login());
localMemory.write('showSplashScreen', false);
},
child: const Text(
'Get Started',
style: TextStyle(
fontFamily: 'Mulish',
fontWeight: FontWeight.bold,
fontSize: 18),
)),
),
],
),
),
],
);
}
}
Its playing all videos in emulator but not local or url mp4 videos, play a local mp4 videos in flutter. If anyone knows, kindly provide the solution or any type of other depedency