在一個flutter項目中,使用了VideoThumbnail來生成視頻的截圖,但運行會提示“No implementation found for method file on channel video_thumbnail”,相當代碼如下:
final thumbnailPath = await VideoThumbnail.thumbnailFile( video: video.url, thumbnailPath: (await getTemporaryDirectory()).path, imageFormat: ImageFormat.WEBP, maxHeight: height, maxWidth: width, // specify the height of the thumbnail, let the width auto-scaled to keep the source aspect ratio quality: 75, );
查看video.url,可以在瀏覽器中打開。發現是http開頭的,估計是android9.x(api27及以上)默認不允許http請求。使用API23的模擬器確實可以正常跑,於是打開android\app\src\main\AndroidManifest.xml,在其application添加
android:usesCleartextTraffic="true"
問題解決。以下是我使用的環境
Android Studio 4.1.2
Flutter 2.0.1