VideoPlayerController.network() 运行 进入源错误
VideoPlayerController.network() ran into source error
我正在尝试使用 VideoPlayerController.netWork() 方法从互联网播放视频,但我尝试的每个 url 都遇到以下指定的错误:
来源错误。
E/flutter ( 4250): [错误:flutter/lib/ui/ui_dart_state.cc(157)] 未处理的异常: PlatformException(VideoError, 视频播放器有错误 com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException:无法连接到 https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4,空)
E/flutter ( 4250): #0 ChewieController._initialize (包:chewie/src/chewie_player.dart:291:7)
E/flutter ( 4250):
E/flutter ( 4250): #1 new ChewieController (package:chewie/src/chewie_player.dart:197:5)
E/flutter ( 4250): #2 _ChewieListState.initState (包:flutterappvideoandshit/screens/chewie_list.dart:20:25)
E/flutter ( 4250): #3 StatefulElement._firstBuild (包:flutter/src/widgets/framework.dart:4640:58)
E/flutter ( 4250): #4 ComponentElement.mount (包:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #5 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #6 Element.updateChild (包:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #7 SingleChildRenderObjectElement.mount (包:flutter/src/widgets/framework.dart:5830:14)
E/flutter ( 4250): #8 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #9 Element.updateChild (包:flutter/src/widgets/framework.dart:3214:18)
E/flutter(4250):#10 SingleChildRenderObjectElement.mount(包:flutter/src/widgets/framework.dart:5830:14)
E/flutter ( 4250): #11 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #12 Element.updateChild (包:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #13 ComponentElement.performRebuild (包:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #14 Element.rebuild (包:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #15 ComponentElement._firstBuild (包:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #16 ComponentElement.mount (包:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #17 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #18 Element.updateChild (包:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #19 ComponentElement.performRebuild (包:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #20 Element.rebuild (包:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #21 ComponentElement._firstBuild (包:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #22 ComponentElement.mount (包:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #23 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14)
E/flutter(4250):#24Element.updateChild(包:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #25 ComponentElement.performRebuild (包:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #26 StatefulElement.performRebuild (包:flutter/src/widgets/framework.dart:4675:11)
E/flutter ( 4250): #27 Element.rebuild (包:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #28 ComponentElement._firstBuild (包:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #29 StatefulElement._firstBuild (包:flutter/src/widgets/framework.dart:4666:11)
E/flutter ( 4250): #30 ComponentElement.mount (包:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #31 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14)
E/flutter(4250):#32Element.updateChild(包:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #33 ComponentElement.performRebuild (包:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #34 Element.rebuild (包:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #35 ComponentElement._firstBuild (包:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #36 ComponentElement.mount (包:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #37 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #38 Element.updateChild (包:flutter/src/widgets/framework.dart:3214:18)
E/flutter(4250):#39 SliverMultiBoxAdaptorElement.updateChild(包:flutter/src/widgets/sliver.dart:1147:36)
E/flutter ( 4250): #40 SliverMultiBoxAdaptorElement.createChild。 (包:flutter/src/widgets/sliver.dart:1132:20)
E/flutter ( 4250): #41 BuildOwner.buildScope (包:flutter/src/widgets/framework.dart:2607:19)
这是我的代码:
import 'package:video_player/video_player.dart';
import 'package:chewie/chewie.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Video Player"),
),
body: ListView(
children: <Widget>[
ChewieList(
videoPlayerController: VideoPlayerController.asset('assets/videos/soccer.mp4'),
looping: true,
),
ChewieList(
videoPlayerController: VideoPlayerController.network(
'https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
),
/*
ChewieList(
videoPlayerController: VideoPlayerController.network(
'http://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
)
*/
],
),
);
}
}
class ChewieList extends StatefulWidget {
ChewieList({@required this.videoPlayerController,this.looping,Key key,}) : super(key:key);
final VideoPlayerController videoPlayerController;
final bool looping;
@override
_ChewieListState createState() => _ChewieListState();
}
class _ChewieListState extends State<ChewieList> {
ChewieController _chewieController;
@override
void initState() {
// TODO: implement initState
super.initState();
_chewieController = ChewieController(
videoPlayerController: widget.videoPlayerController,
aspectRatio: 16/9,
autoInitialize: true,
looping: widget.looping,
errorBuilder: (context,errMsg){
return Center(
child:Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.warning,color: Colors.yellowAccent,),
Text("!خطایی در برقراری ارتباط رخ داده است",style: TextStyle(color: Colors.white),)
],
),
);
}
);
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
widget.videoPlayerController.dispose();
_chewieController.dispose();
}
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(8.0),
child: Chewie(
controller: _chewieController,
),
);
}
}
快把我逼疯了!!!!
伙计们请帮助我。
你用错了url。您发布的 url 不是真实视频 url 而只是重定向 url.
试试:
VideoPlayerController.network('https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
(请记住,iOS 模拟器和其他并不总是支持视频播放。)
我正在尝试使用 VideoPlayerController.netWork() 方法从互联网播放视频,但我尝试的每个 url 都遇到以下指定的错误:
来源错误。 E/flutter ( 4250): [错误:flutter/lib/ui/ui_dart_state.cc(157)] 未处理的异常: PlatformException(VideoError, 视频播放器有错误 com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException:无法连接到 https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4,空) E/flutter ( 4250): #0 ChewieController._initialize (包:chewie/src/chewie_player.dart:291:7) E/flutter ( 4250): E/flutter ( 4250): #1 new ChewieController (package:chewie/src/chewie_player.dart:197:5) E/flutter ( 4250): #2 _ChewieListState.initState (包:flutterappvideoandshit/screens/chewie_list.dart:20:25) E/flutter ( 4250): #3 StatefulElement._firstBuild (包:flutter/src/widgets/framework.dart:4640:58) E/flutter ( 4250): #4 ComponentElement.mount (包:flutter/src/widgets/framework.dart:4476:5) E/flutter ( 4250): #5 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14) E/flutter ( 4250): #6 Element.updateChild (包:flutter/src/widgets/framework.dart:3214:18) E/flutter ( 4250): #7 SingleChildRenderObjectElement.mount (包:flutter/src/widgets/framework.dart:5830:14) E/flutter ( 4250): #8 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14) E/flutter ( 4250): #9 Element.updateChild (包:flutter/src/widgets/framework.dart:3214:18) E/flutter(4250):#10 SingleChildRenderObjectElement.mount(包:flutter/src/widgets/framework.dart:5830:14) E/flutter ( 4250): #11 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14) E/flutter ( 4250): #12 Element.updateChild (包:flutter/src/widgets/framework.dart:3214:18) E/flutter ( 4250): #13 ComponentElement.performRebuild (包:flutter/src/widgets/framework.dart:4527:16) E/flutter ( 4250): #14 Element.rebuild (包:flutter/src/widgets/framework.dart:4218:5) E/flutter ( 4250): #15 ComponentElement._firstBuild (包:flutter/src/widgets/framework.dart:4481:5) E/flutter ( 4250): #16 ComponentElement.mount (包:flutter/src/widgets/framework.dart:4476:5) E/flutter ( 4250): #17 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14) E/flutter ( 4250): #18 Element.updateChild (包:flutter/src/widgets/framework.dart:3214:18) E/flutter ( 4250): #19 ComponentElement.performRebuild (包:flutter/src/widgets/framework.dart:4527:16) E/flutter ( 4250): #20 Element.rebuild (包:flutter/src/widgets/framework.dart:4218:5) E/flutter ( 4250): #21 ComponentElement._firstBuild (包:flutter/src/widgets/framework.dart:4481:5) E/flutter ( 4250): #22 ComponentElement.mount (包:flutter/src/widgets/framework.dart:4476:5) E/flutter ( 4250): #23 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14) E/flutter(4250):#24Element.updateChild(包:flutter/src/widgets/framework.dart:3214:18) E/flutter ( 4250): #25 ComponentElement.performRebuild (包:flutter/src/widgets/framework.dart:4527:16) E/flutter ( 4250): #26 StatefulElement.performRebuild (包:flutter/src/widgets/framework.dart:4675:11) E/flutter ( 4250): #27 Element.rebuild (包:flutter/src/widgets/framework.dart:4218:5) E/flutter ( 4250): #28 ComponentElement._firstBuild (包:flutter/src/widgets/framework.dart:4481:5) E/flutter ( 4250): #29 StatefulElement._firstBuild (包:flutter/src/widgets/framework.dart:4666:11) E/flutter ( 4250): #30 ComponentElement.mount (包:flutter/src/widgets/framework.dart:4476:5) E/flutter ( 4250): #31 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14) E/flutter(4250):#32Element.updateChild(包:flutter/src/widgets/framework.dart:3214:18) E/flutter ( 4250): #33 ComponentElement.performRebuild (包:flutter/src/widgets/framework.dart:4527:16) E/flutter ( 4250): #34 Element.rebuild (包:flutter/src/widgets/framework.dart:4218:5) E/flutter ( 4250): #35 ComponentElement._firstBuild (包:flutter/src/widgets/framework.dart:4481:5) E/flutter ( 4250): #36 ComponentElement.mount (包:flutter/src/widgets/framework.dart:4476:5) E/flutter ( 4250): #37 Element.inflateWidget (包:flutter/src/widgets/framework.dart:3446:14) E/flutter ( 4250): #38 Element.updateChild (包:flutter/src/widgets/framework.dart:3214:18) E/flutter(4250):#39 SliverMultiBoxAdaptorElement.updateChild(包:flutter/src/widgets/sliver.dart:1147:36) E/flutter ( 4250): #40 SliverMultiBoxAdaptorElement.createChild。 (包:flutter/src/widgets/sliver.dart:1132:20) E/flutter ( 4250): #41 BuildOwner.buildScope (包:flutter/src/widgets/framework.dart:2607:19)
这是我的代码:
import 'package:video_player/video_player.dart';
import 'package:chewie/chewie.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Video Player"),
),
body: ListView(
children: <Widget>[
ChewieList(
videoPlayerController: VideoPlayerController.asset('assets/videos/soccer.mp4'),
looping: true,
),
ChewieList(
videoPlayerController: VideoPlayerController.network(
'https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
),
/*
ChewieList(
videoPlayerController: VideoPlayerController.network(
'http://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
)
*/
],
),
);
}
}
class ChewieList extends StatefulWidget {
ChewieList({@required this.videoPlayerController,this.looping,Key key,}) : super(key:key);
final VideoPlayerController videoPlayerController;
final bool looping;
@override
_ChewieListState createState() => _ChewieListState();
}
class _ChewieListState extends State<ChewieList> {
ChewieController _chewieController;
@override
void initState() {
// TODO: implement initState
super.initState();
_chewieController = ChewieController(
videoPlayerController: widget.videoPlayerController,
aspectRatio: 16/9,
autoInitialize: true,
looping: widget.looping,
errorBuilder: (context,errMsg){
return Center(
child:Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.warning,color: Colors.yellowAccent,),
Text("!خطایی در برقراری ارتباط رخ داده است",style: TextStyle(color: Colors.white),)
],
),
);
}
);
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
widget.videoPlayerController.dispose();
_chewieController.dispose();
}
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(8.0),
child: Chewie(
controller: _chewieController,
),
);
}
}
快把我逼疯了!!!! 伙计们请帮助我。
你用错了url。您发布的 url 不是真实视频 url 而只是重定向 url.
试试:
VideoPlayerController.network('https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
(请记住,iOS 模拟器和其他并不总是支持视频播放。)