@@ -12,6 +12,7 @@ import { addAudioUrl, addImageUrl, addOutOfMemoryUrl, addVideoUrl } from '../../
12
12
import Engine from '../../../core/Engine' ;
13
13
import { colors } from '../../../styles/common' ;
14
14
import { isImageFile , isMp3File , isSvgFile , isVideoFile } from '../../../util/general' ;
15
+ import Device from '../../../util/Device' ;
15
16
import SvgImage from '../SvgImage' ;
16
17
17
18
export const convertImageUrl = imageUrl => {
@@ -68,7 +69,8 @@ class NFTImage extends PureComponent {
68
69
resizeMode : PropTypes . string ,
69
70
isBlurBg : PropTypes . bool ,
70
71
svgUseWebView : PropTypes . bool ,
71
- isThumbnail : PropTypes . bool
72
+ isThumbnail : PropTypes . bool ,
73
+ videoThumbnail : PropTypes . any
72
74
} ;
73
75
74
76
state = {
@@ -78,7 +80,8 @@ class NFTImage extends PureComponent {
78
80
isSvgUrl : false ,
79
81
imageLoadingError : false ,
80
82
defaultLoadingError : false ,
81
- parseError : false
83
+ parseError : false ,
84
+ videoError : false
82
85
} ;
83
86
84
87
refImage = React . createRef ( ) ;
@@ -97,6 +100,7 @@ class NFTImage extends PureComponent {
97
100
addAudioUrl,
98
101
addOutOfMemoryUrl
99
102
} = this . props ;
103
+
100
104
if ( isImageFile ( urlValue ) || imageUrls . indexOf ( urlValue ) !== - 1 ) {
101
105
this . setState ( { isImageUrl : true } ) ;
102
106
// eslint-disable-next-line no-empty
@@ -108,10 +112,13 @@ class NFTImage extends PureComponent {
108
112
} else if ( isSvgFile ( urlValue ) ) {
109
113
} else {
110
114
const task = RNFetchBlob . fetch ( 'GET' , urlValue ) ;
111
- task . then ( res => {
115
+
116
+ task . then ( async res => {
112
117
const status = res . info ( ) ?. status ;
118
+
113
119
if ( status === 200 ) {
114
120
const contentType = res . info ( ) ?. headers [ 'Content-Type' ] ?. toLowerCase ( ) ;
121
+
115
122
if ( contentType ) {
116
123
if ( contentType . startsWith ( 'video/' ) ) {
117
124
this . setState ( { isVideoUrl : true } ) ;
@@ -131,6 +138,33 @@ class NFTImage extends PureComponent {
131
138
addOutOfMemoryUrl ( urlValue ) ;
132
139
}
133
140
}
141
+
142
+ //Fallback call only on android
143
+ if ( Device . isAndroid ( ) ) {
144
+ if ( ! status || status !== 200 ) {
145
+ const response = await fetch ( urlValue , { method : 'HEAD' } ) ;
146
+ const contentType = response . headers . get ( 'Content-Type' ) ;
147
+ if ( contentType ) {
148
+ if ( contentType . startsWith ( 'video/' ) ) {
149
+ this . setState ( { isVideoUrl : true } ) ;
150
+ addVideoUrl ( urlValue ) ;
151
+ } else if ( contentType . startsWith ( 'image/' ) ) {
152
+ this . setState ( { isImageUrl : true } ) ;
153
+ addImageUrl ( urlValue ) ;
154
+ } else if ( contentType . startsWith ( 'audio/' ) ) {
155
+ this . setState ( { isAudioUrl : true } ) ;
156
+ addAudioUrl ( urlValue ) ;
157
+ }
158
+ }
159
+
160
+ if (
161
+ response . headers . get ( 'Content-Length' ) &&
162
+ response . headers . get ( 'Content-Length' ) > 1024 * 1024 * 3
163
+ ) {
164
+ addOutOfMemoryUrl ( urlValue ) ;
165
+ }
166
+ }
167
+ }
134
168
} ) . catch ( err => {
135
169
console . error ( err ) ;
136
170
} ) ;
@@ -143,6 +177,10 @@ class NFTImage extends PureComponent {
143
177
}
144
178
} ;
145
179
180
+ handleVideoError = ( ) => {
181
+ this . setState ( { videoError : true } ) ;
182
+ } ;
183
+
146
184
render ( ) {
147
185
const {
148
186
style,
@@ -218,18 +256,34 @@ class NFTImage extends PureComponent {
218
256
} else if ( isVideoUrl || isVideoFile ( urlValue ) ) {
219
257
return (
220
258
< View style = { [ style , showBorder && styles . borderStyle , isBlurBg && styles . bgBlack ] } >
221
- < Video
222
- muted
223
- source = { { uri : convertToProxyURL ( urlValue ) } }
224
- style = { [ { width, height } , styles . videoLayout ] } //组件样式
225
- mixWithOthers = { 'mix' }
226
- useTextureView
227
- playWhenInactive
228
- playInBackground
229
- ignoreSilentSwitch = "ignore"
230
- disableFocus
231
- repeat
232
- />
259
+ { this . state . videoError && this . props . videoThumbnail ? (
260
+ < Video
261
+ muted
262
+ source = { { uri : convertToProxyURL ( convertImageUrl ( this . props . videoThumbnail ) ) } }
263
+ style = { [ { width, height } , styles . videoLayout ] }
264
+ mixWithOthers = { 'mix' }
265
+ useTextureView
266
+ playWhenInactive
267
+ playInBackground
268
+ ignoreSilentSwitch = "ignore"
269
+ disableFocus
270
+ repeat
271
+ />
272
+ ) : (
273
+ < Video
274
+ muted
275
+ source = { { uri : convertToProxyURL ( urlValue ) } }
276
+ style = { [ { width, height } , styles . videoLayout ] }
277
+ mixWithOthers = { 'mix' }
278
+ useTextureView
279
+ playWhenInactive
280
+ playInBackground
281
+ ignoreSilentSwitch = "ignore"
282
+ disableFocus
283
+ repeat
284
+ onError = { this . handleVideoError }
285
+ />
286
+ ) }
233
287
</ View >
234
288
) ;
235
289
} else if ( isSvgUrl || isSvgFile ( urlValue ) ) {
0 commit comments