I am trying to play mp4 videos from network using video_player dependency in flutter(running my app only on android), the video don't playing and the app crashing after few seconds. I am trying to run the app on API 19 max.
here is my code:
import 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';
void main() => runApp(VideoApp());
class VideoApp extends StatefulWidget {
@override
_VideoAppState createState() => _VideoAppState();
}
class _VideoAppState extends State<VideoApp> {
VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4')
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Video Demo',
home: Scaffold(
body: Center(
child: _controller.value.initialized
? AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: Container(),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
_controller.value.isPlaying
? _controller.pause()
: _controller.play();
});
},
child: Icon(
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
),
),
),
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
}
here is the output:
D/ ( 4654): HostConnection::get() New Host Connection established 0xb7b11d20, tid 4669
D/dalvikvm( 4654): GC_CONCURRENT freed 231K, 8% free 3676K/3980K, paused 1ms+1ms, total 4ms
E/ExoPlayerImplInternal( 4654): Source error.
E/ExoPlayerImplInternal( 4654): com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4
E/ExoPlayerImplInternal( 4654): at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:281)
E/ExoPlayerImplInternal( 4654): at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83)
E/ExoPlayerImplInternal( 4654): at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:885)
E/ExoPlayerImplInternal( 4654): at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381)
E/ExoPlayerImplInternal( 4654): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/ExoPlayerImplInternal( 4654): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/ExoPlayerImplInternal( 4654): at java.lang.Thread.run(Thread.java:841)
E/ExoPlayerImplInternal( 4654): Caused by: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb7b30750: Failure in SSL library, usually a protocol error
E/ExoPlayerImplInternal( 4654): error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0x8d995990:0x00000000)
E/ExoPlayerImplInternal( 4654): at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:448)
E/ExoPlayerImplInternal( 4654): at com.android.okhttp.Connection.upgradeToTls(Connection.java:146)
E/ExoPlayerImplInternal( 4654): at com.android.okhttp.Connection.connect(Connection.java:107)
E/ExoPlayerImplInternal( 4654): at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
E/ExoPlayerImplInternal( 4654): at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
E/ExoPlayerImplInternal( 4654): at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
E/ExoPlayerImplInternal( 4654): at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
E/ExoPlayerImplInternal( 4654): at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
E/ExoPlayerImplInternal( 4654): at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:161)
E/ExoPlayerImplInternal( 4654): at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.makeConnection(DefaultHttpDataSource.java:528)
E/ExoPlayerImplInternal( 4654): at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.makeConnection(DefaultHttpDataSource.java:444)
E/ExoPlayerImplInternal( 4654): at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:279)
E/ExoPlayerImplInternal( 4654): ... 6 more
E/ExoPlayerImplInternal( 4654): Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb7b30750: Failure in SSL library, usually a protocol error
E/ExoPlayerImplInternal( 4654): error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0x8d995990:0x00000000)
E/ExoPlayerImplInternal( 4654): at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
E/ExoPlayerImplInternal( 4654): at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:405)
E/ExoPlayerImplInternal( 4654): ... 17 more
E/flutter ( 4654): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4, null)
E/flutter ( 4654):
E/flutter ( 5040): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to http://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4, null)
E/flutter ( 5040):
E/flutter ( 5097): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to http://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4, null)
E/flutter ( 5097):
E/flutter ( 5176): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to http://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4, null)
E/flutter ( 5176):
E/flutter ( 5268): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to http://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4, null)
I'm able to run the sample you've provided without issues using video_player: ^2.3.0
. Try updating the version that you're using.
Also, here's the defaultConfig on my build.gradle
defaultConfig {
applicationId "your.package.name"
minSdkVersion 19
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}