Youtube_player_flutter: Thumbnail 404 errors causes exceptions

Created on 5 Mar 2020  ยท  9Comments  ยท  Source: sarbagyastha/youtube_player_flutter

I quite often get the following expcetion when opening videos:


โ•โ•โ•โ•โ•โ•โ•โ• Exception caught by image resource service โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
The following NetworkImageLoadException was thrown resolving an image codec:
HTTP request failed, statusCode: 404, https://i3.ytimg.com/vi_webp/BP979AMuuP8/sddefault.webp

When the exception was thrown, this was the stack
#0      NetworkImage._loadAsync 
package:flutter/โ€ฆ/painting/_network_image_io.dart:90
<asynchronous suspension>
#1      NetworkImage.load 
package:flutter/โ€ฆ/painting/_network_image_io.dart:47
#2      ImageProvider.resolveStreamForKey.<anonymous closure> 
package:flutter/โ€ฆ/painting/image_provider.dart:491
#3      ImageCache.putIfAbsent 
package:flutter/โ€ฆ/painting/image_cache.dart:344
...
Image provider: NetworkImage("https://i3.ytimg.com/vi_webp/BP979AMuuP8/sddefault.webp", scale: 1.0)
Image key: NetworkImage("https://i3.ytimg.com/vi_webp/BP979AMuuP8/sddefault.webp", scale: 1.0)

I think the thumbnail image needs to be loaded in a way to handle 404 errors.

bug

Most helpful comment

no .. it shows whatever you set in thumbnail. If you dont set it, then it will show whatever it get from the video.. I do this

thumbnailUrl: "https://img.youtube.com/vi/${widget.videoID}/hqdefault.jpg",

All 9 comments

Having the same issue... there must be a way to add Alternative thumbnail image if the youtube video doesn't have one.

@jwhijazi you can specify a thumbnail for the video, although if you do it will not attempt to fetch the youtube one.

The behavior you have described is possible but it would require the YT thumbnail to be loaded in a different way to catch the 404 and then use the fallback image. I'm a bit too busy at the moment otherwise I would implement this.

@jimmyff
No problem... Once you have time it will be a good fix.
Thanks,

Same, anyone have a solution?

this is how i solved the problem. The problem is that if you hit the above URL few times, then it blocks the client, hence the error.

However, Youtube provide's thumbnail images for all its videos. Just insert the videoID in the provided URL.

YoutubePlayer( controller: _controller, thumbnailUrl: "https://img.youtube.com/vi/${videoID}/hqdefault.jpg", )

@dheerajsarwaiya there is no param for thumbnailUrl in the plugin, can you please describe the same, I'm getting the same exception again and again.

After 7.0.0+2 he removed the thumbnailUrl. Now you can use any widget in thumbnail parameter.

Added thumbnail parameter to YoutubePlayer, removed thumbnailUrl. Now any widget can be used as thumbnail.

@dheerajsarwaiya If I'm getting it correct, the thumbnail param only shows the respective widget till the youtube player loads the correct thumbnail. Correct me if I'm wrong.

no .. it shows whatever you set in thumbnail. If you dont set it, then it will show whatever it get from the video.. I do this

thumbnailUrl: "https://img.youtube.com/vi/${widget.videoID}/hqdefault.jpg",

Was this page helpful?
0 / 5 - 0 ratings