你好朋友,我正在使用youtube播放器插件播放youtube视频,我也从youtube链接中获取了一些缩略图的问题是,当我尝试播放youtube视频时,它在Android上可以正常使用,但在iphone上,它不能在全Sacreen模式下播放,我尝试获取日志我在console.in DetailPage中收到此日志,如果新闻类型是图像,则获取图像,如果类型是视频,则获取图像,获取所有youtube视频缩略图,其工作正常并获取所有缩略图,但请给出例外,我所关注的不是解决此例外,我所关注的在ios上播放完整视频
════════ Exception caught by image resource service ════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/ypf.png
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:664:31)
#2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:648:14)
#3 ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:501:13)
...
Image provider: AssetImage(bundle: null, name: "assets/ypf.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#5acb7(), name: "assets/ypf.png", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
The following NetworkImageLoadException was thrown resolving an image codec:
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/exbwhvgPIyo/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
When the exception was thrown, this was the stack:
#0 NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:95:9)
<asynchronous suspension>
#1 NetworkImage.load (package:flutter/src/painting/_network_image_io.dart:48:14)
#2 ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:501:13)
#3 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:359:22)
...
Image provider: NetworkImage("https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/exbwhvgPIyo/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg", scale: 1.0)
Image key: NetworkImage("https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/exbwhvgPIyo/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg", scale: 1.0)
═══════════════════════════════════════════════ ══════════════════════════════════════════════════ ═══
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/uYCshzLDOpA/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/5yzW1r0zXQI/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/D6ACmdU3jas/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/qGaQso9SvPY/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
═════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/IKHsljZg3as/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
════════图像资源服务捕获的异常═════════════════════════════════ ═══════════════ HTTP请求失败,statusCode:404,https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/SWw62MlahFw/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg ══════════════════════════════════════════════════ ══════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/tWjW0tupH44/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/Q6W0QOJuGWs/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/uYCshzLDOpA/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
The following NetworkImageLoadException was thrown resolving an image codec:
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/esuLRQjD6fU/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
When the exception was thrown, this was the stack:
#0 NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:95:9)
<asynchronous suspension>
#1 NetworkImage.load (package:flutter/src/painting/_network_image_io.dart:48:14)
#2 ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:501:13)
#3 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:359:22)
...
Image provider: NetworkImage("https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/esuLRQjD6fU/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg", scale: 1.0)
Image key: NetworkImage("https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/esuLRQjD6fU/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/5yzW1r0zXQI/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/5w7oFE06GyM/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/SWw62MlahFw/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/54DFanTEHQA/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/qGaQso9SvPY/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/QJl0AZGdneM/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
HTTP request failed, statusCode: 404, https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/https://img.youtube.com/vi/3V2KSFeabkM/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg/hqdefault.jpg
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'dart:async';
import 'dart:convert';
import 'package:tv/ImageDetails.dart';
import 'package:tv/video.dart';
class DetailPage extends StatefulWidget {
final String id;
final String title;
DetailPage(this.id, this.title);
@override
_DetailPageState createState() => _DetailPageState();
}
class _DetailPageState extends State<DetailPage> {
bool _loading=true;
Map data;
List userData;
String image;
Future getData() async {
String id=widget.id;
http.Response response = await http.get("http://lhtvapp.com//api.php?cat_id=$id");
data = json.decode(response.body);
//debugPrint(response.body);
print(id);
setState(() {
userData = data["NEWS_APP"];
_loading=false;
});
}
@override
void initState() {
// TODO: implement initState
super.initState();
getData();
}
@override
Widget build(BuildContext context) {
String title=widget.title;
return Scaffold(
appBar: AppBar(
backgroundColor:Colors.white,
automaticallyImplyLeading:true,
leading: IconButton(
icon:Icon(
Icons.arrow_back_ios,color: Colors.amber[800]),
onPressed: () => Navigator.of(context).pop(),
),
elevation: 0.0,
title:Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset(
'images/logo.png',
height: 100,
),
],
)
),
body:_loading ? Center(
child: Container(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.amber[800]),
),
),
) :
Padding(
padding: EdgeInsets.all(8.0),
child: Container(
child: Column(
children: <Widget>[
Text(title,style:TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold
),),
SizedBox(height: 10,),
Text('So faith comes from hearing, and hearing through the word of Christ (Romans 10:17)'
,style:TextStyle(
color: Colors.black54,
fontWeight: FontWeight.bold
),),
SizedBox(height: 10,),
Expanded(
child: GridView.builder(
padding:EdgeInsets.only(top:12),
shrinkWrap: true,
itemCount:userData == null ? 0 : userData.length,
gridDelegate:new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (BuildContext context,int index){
String new_type=userData[index]['news_type'];
if(new_type=="image") {
image = userData[index]['news_image_b'];
}
else
{
String thumb=userData[index]['video_id'];
image=userData[index]['video_id']='https://img.youtube.com/vi/${thumb}/hqdefault.jpg';
}
return new GestureDetector(
onTap: (){
new_type=userData[index]['news_type'];
if(new_type=="image"){
String des=userData[index]['news_description'];
Navigator.of(context).push(MaterialPageRoute(
builder:(context)=>ImageDetails(userData[index]['id'],userData[index]['news_title'],userData[index]['news_image_s'],userData[index]['news_description']),
)
);
}else{
Navigator.of(context).push(MaterialPageRoute(
builder:(context)=>Video(userData[index]['video_url'],userData[index]['news_title'],userData[index]['news_description']),
)
);
}
},
child: new Card(
shape:RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: new Container(
alignment: Alignment.center,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded
(child:
ClipRRect(
borderRadius: BorderRadius.circular(10.0),
child: Image.network(image,fit: BoxFit.cover,))),
Center(
child: Container(
child: Text(userData[index]["news_title"],style:TextStyle(
fontSize:11,
fontWeight:FontWeight.bold
),),
),
)
],
),
),
),
);
},
),
),
],
),
),
/* child:GridView.builder(
itemCount: 20,
gridDelegate:new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (BuildContext context,int index){
return new GestureDetector(
child: new Card(
child: new Container(
child: Column(
children: <Widget>[
Text('Item $index')
],
),
0 ),
),
);
},
),*/
),
);
}
}
import 'dart:developer';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:youtube_player_flutter/youtube_player_flutter.dart';
/// Creates [YoutubePlayerDemoApp] widget.
class YoutubePlayerDemoApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Video('video','title','des'),
);
}
}
/// Homepage
class Video extends StatefulWidget {
String videourl;
String title;
String des;
@override
_VideoState createState() => _VideoState();
Video(this.videourl, this.title, this.des);
}
class _VideoState extends State<Video> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
YoutubePlayerController _controller;
TextEditingController _idController;
TextEditingController _seekToController;
PlayerState _playerState;
YoutubeMetaData _videoMetaData;
double _volume = 100;
bool _muted = false;
bool _isPlayerReady = false;
final List<String> _ids = [
];
@override
void initState() {
WidgetsFlutterBinding.ensureInitialized();
super.initState();
_controller = YoutubePlayerController(
initialVideoId:YoutubePlayer.convertUrlToId(widget.videourl),
flags: const YoutubePlayerFlags(
mute: false,
autoPlay: true,
disableDragSeek: false,
loop: false,
isLive: false,
forceHD: true,
enableCaption: true,
),
)..addListener(listener);
_idController = TextEditingController();
_seekToController = TextEditingController();
_videoMetaData = const YoutubeMetaData();
_playerState = PlayerState.unknown;
}
void listener() {
if (_isPlayerReady && mounted && !_controller.value.isFullScreen) {
setState(() {
_playerState = _controller.value.playerState;
_videoMetaData = _controller.metadata;
});
}
}
@override
void deactivate() {
// Pauses video while navigating to next page.
_controller.pause();
super.deactivate();
}
@override
void dispose() {
_controller.dispose();
_idController.dispose();
_seekToController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return YoutubePlayerBuilder(
onExitFullScreen: () {
// The player forces portraitUp after exiting fullscreen. This overrides the behaviour.
SystemChrome.setPreferredOrientations(DeviceOrientation.values);
},
player: YoutubePlayer(
controller: _controller,
showVideoProgressIndicator: true,
progressIndicatorColor: Colors.blueAccent,
topActions: <Widget>[
const SizedBox(width: 8.0),
Expanded(
child: Text(
_controller.metadata.title,
style: const TextStyle(
color: Colors.white,
fontSize: 18.0,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
],
onReady: () {
_isPlayerReady = true;
},
onEnded: (data) {
_controller
.load(_ids[(_ids.indexOf(data.videoId) + 1) % _ids.length]);
_showSnackBar('Next Video Started!');
},
),
builder: (context, player) => Scaffold(
key: _scaffoldKey,
appBar: AppBar(
backgroundColor:Colors.white,
automaticallyImplyLeading:true,
leading: IconButton(
icon:Icon(
Icons.arrow_back_ios,color: Colors.amber[800]),
onPressed: () => Navigator.of(context).pop(),
),
elevation: 0.0,
title:Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset(
'images/logo.png',
height: 100,
),
],
)
),
body: ListView(
children: [
player,
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_space,
_text('Title', _videoMetaData.title
),
_space,
_space,
_space,
_space,
_space,
_space,
_space,
_space,
AnimatedContainer(
duration: const Duration(milliseconds: 800),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
),
padding: const EdgeInsets.all(8.0),
child: Text(
_playerState.toString(),
style: const TextStyle(
fontWeight: FontWeight.w300,
color: Colors.white,
),
textAlign: TextAlign.center,
),
),
],
),
),
],
),
),
);
}
Widget _text(String title, String value) {
return RichText(
text: TextSpan(
text: '$title : ',
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
children: [
TextSpan(
text: value ?? '',
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.w300,
),
),
],
),
);
}
/* Color _getStateColor(PlayerState state) {
switch (state) {
case PlayerState.unknown:
return Colors.grey[700];
case PlayerState.unStarted:
return Colors.pink;
case PlayerState.ended:
return Colors.red;
case PlayerState.playing:
return Colors.blueAccent;
case PlayerState.paused:
return Colors.orange;
case PlayerState.buffering:
return Colors.yellow;
case PlayerState.cued:
return Colors.blue[900];
default:
return Colors.blue;
}
}*/
Widget get _space => const SizedBox(height: 10);
Widget _loadCueButton(String action) {
return Expanded(
child: MaterialButton(
color: Colors.blueAccent,
onPressed: _isPlayerReady
? () {
if (_idController.text.isNotEmpty) {
var id = YoutubePlayer.convertUrlToId(
_idController.text,
);
if (action == 'LOAD') _controller.load(id);
if (action == 'CUE') _controller.cue(id);
FocusScope.of(context).requestFocus(FocusNode());
} else {
_showSnackBar('Source can\'t be empty!');
}
}
: null,
disabledColor: Colors.grey,
disabledTextColor: Colors.black,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 14.0),
child: Text(
action,
style: const TextStyle(
fontSize: 18.0,
color: Colors.white,
fontWeight: FontWeight.w300,
),
textAlign: TextAlign.center,
),
),
),
);
}
void _showSnackBar(String message) {
_scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Text(
message,
textAlign: TextAlign.center,
style: const TextStyle(
fontWeight: FontWeight.w300,
fontSize: 16.0,
),
),
backgroundColor: Colors.blueAccent,
behavior: SnackBarBehavior.floating,
elevation: 1.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50.0),
),
),
);
}
}