-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chooseVideo 没有在 Safari 中正确触发回调 #14678
Comments
taro/packages/taro-h5/src/api/media/video/chooseMedia.ts Lines 146 to 164 in 180c9e4
问题已经找到,因为 safari 下,永远不会触发 应该是不支持播放 |
已经解决,在 Reader 的 onload 事件 resolve 之后即可 // 对齐旧版本实现
reader.onload = (event) => {
res.tempFilePath = event.target?.result as string
+ resolve(res)
} 另外为了 diff --git a/node_modules/@tarojs/taro-h5/dist/api/media/video/chooseMedia.js b/node_modules/@tarojs/taro-h5/dist/api/media/video/chooseMedia.js
index 7227c70..dbfe8f4 100644
--- a/node_modules/@tarojs/taro-h5/dist/api/media/video/chooseMedia.js
+++ b/node_modules/@tarojs/taro-h5/dist/api/media/video/chooseMedia.js
@@ -134,24 +134,53 @@ const chooseMedia = function (options, methodName = 'chooseMedia') {
video.crossOrigin = 'Anonymous';
video.preload = 'metadata';
video.src = res.tempFilePath;
+
+ const canPlay = video.canPlayType(file.type);
+
+
+ if (canPlay === 'probably') {
+ console.log('浏览器可能支持播放该视频类型。');
+ } else if (canPlay === 'maybe') {
+ console.log('浏览器可能支持播放该视频类型,但不确定性较大。');
+ } else {
+ console.log('浏览器不支持播放该视频类型。');
+ }
+
return new Promise((resolve, reject) => {
- // 对齐旧版本实现
- reader.onload = (event) => {
- var _a;
- res.tempFilePath = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
- };
+ switch (canPlay) {
+ case 'probably':
+ // 对齐旧版本实现
+ reader.onload = (event) => {
+ var _a;
+ res.tempFilePath = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
+ resolve(res)
+ };
+ video.onloadedmetadata = () => {
+ res.duration = video.duration;
+ res.height = video.videoHeight;
+ res.width = video.videoWidth;
+ };
+ video.oncanplay = () => {
+ res.thumbTempFilePath = getThumbTempFilePath(video, res.height, res.width, 0.8);
+ resolve(res);
+ };
+ video.onerror = e => reject(e);
+ break
+ case 'maybe':
+ default:
+ // 对齐旧版本实现
+ reader.onload = (event) => {
+ var _a;
+ res.tempFilePath = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
+
+ resolve(res)
+ };
+ break
+ }
+
reader.onerror = e => reject(e);
reader.readAsDataURL(res.originalFileObj);
- video.onloadedmetadata = () => {
- res.duration = video.duration;
- res.height = video.videoHeight;
- res.width = video.videoWidth;
- };
- video.oncanplay = () => {
- res.thumbTempFilePath = getThumbTempFilePath(video, res.height, res.width, 0.8);
- resolve(res);
- };
- video.onerror = e => reject(e);
+
});
}
else {
|
是的,想不到如今才有人发现这个问题,说明用Taro的人还是很少。 最近写了一个组件库:https://github.com/sutras/sard。 为了兼容H5,专门针对H5自行实现了chooseVideo接口。 |
我在使用Taro.chooseMedia也遇到了这个问题。 |
相关平台
H5
浏览器版本: Safari
使用框架: React
复现步骤
无论是回调的写法,还是 Promise 的写法,都没有回调。
Android 正常
期望结果
.
实际结果
触发了文件选择,选择之后,既没有触发 success,也没有触发 fail
环境信息
The text was updated successfully, but these errors were encountered: