Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

是否能获取网络视频的封面,现在会报错 #50

Open
yuanbolin opened this issue Sep 25, 2019 · 9 comments
Open

是否能获取网络视频的封面,现在会报错 #50

yuanbolin opened this issue Sep 25, 2019 · 9 comments

Comments

@yuanbolin
Copy link

No description provided.

@duongtungls
Copy link

duongtungls commented Sep 27, 2019

你可以用https://github.com/itinance/react-native-fs 下载视频成为一个 file
然后用 RNThumbnail 取thumbnail

const url = '/path/to/remote/file'
const filePath = RNFS.DocumentDirectoryPath + '/video.mp4';

RNFS.downloadFile(url, filePath).promise.then(res => {
  RNThumbnail.get(filePath).then((result) => {
    console.log(result.path); // thumbnail path
  })
});

@yuanbolin
Copy link
Author

会出现偶尔会出错的情况吗,我这边偶尔会失败,

@yuanbolin
Copy link
Author

let thumbnail = await RNThumbnail.get(video.path);
偶尔会失败取不到

@duongtungls
Copy link

@wulala1997 什么原因?有log吗?

try {
  let thumbnail = await RNThumbnail.get(video.path);
} catch (e) {
  console.error(e)
}

会有log

@yuanbolin
Copy link
Author

处理的视频==> file:///storage/emulated/0/Pictures/video-2d880eef-a48a-4087-8239-cd0f2f3704058393300293092977467.mp4

Error: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference
Error: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference
at createErrorFromErrorData (blob:http://localhost:8081/adc8e4f3-6ae3-4477-b98c-04a67572c11c:14608:17)
at blob:http://localhost:8081/adc8e4f3-6ae3-4477-b98c-04a67572c11c:14567:27
at MessageQueue.__invokeCallback (blob:http://localhost:8081/adc8e4f3-6ae3-4477-b98c-04a67572c11c:15429:18)
at blob:http://localhost:8081/adc8e4f3-6ae3-4477-b98c-04a67572c11c:15155:18
at MessageQueue.__guard (blob:http://localhost:8081/adc8e4f3-6ae3-4477-b98c-04a67572c11c:15343:13)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (blob:http://localhost:8081/adc8e4f3-6ae3-4477-b98c-04a67572c11c:15154:14)
at http://localhost:8081/debugger-ui/debuggerWorker.js:80:58

@yuanbolin
Copy link
Author

yuanbolin commented Sep 27, 2019 via email

@duongtungls
Copy link

duongtungls commented Sep 27, 2019

可能是错误在这 image.compress(Bitmap.CompressFormat.JPEG, 100, fOut);

因为

Bitmap image = retriever.getFrameAtTime(1000000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);

所以视频不到1秒那就没有 retriever.getFrameAtTime(1000000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
你检查你的视频是否不到一秒。

@yuanbolin
Copy link
Author

好的,十分感谢.抱歉打扰您中午休息了

@duongtungls
Copy link

没问题,我在越南现在还是工作时间。

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants