File tree 2 files changed +40
-4
lines changed
2 files changed +40
-4
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ interface playerOptions {
63
63
poster? : string ;
64
64
controlBar? : any ;
65
65
notSupportedMessage? : string ;
66
+ suppressNotSupportedError? : Boolean ;
66
67
techOrder? : Array <string >;
67
68
flash? : any ;
68
69
flvjs? : any ;
@@ -197,17 +198,23 @@ class SmVideoPlayer extends Vue {
197
198
});
198
199
}
199
200
201
+ clearSrc() {
202
+ if (this .playerOptions .sources ) {
203
+ this .playerOptions .sources [0 ].src = ' ' ;
204
+ this .modalPlayerOptions .sources [0 ].src = ' ' ;
205
+ }
206
+ }
207
+
200
208
handlePlayerOptions(options = this .options ) {
201
209
if (! this .url ) {
210
+ this .clearSrc ();
211
+ this .playerOptions .suppressNotSupportedError = true ;
202
212
return {};
203
213
}
204
214
if (! this .checkUrl (this .url )) {
205
215
// @ts-ignore
206
216
Message .warning (this .$t (' warning.unsupportedVideoAddress' ), 1 );
207
- if (this .playerOptions .sources ) {
208
- this .playerOptions .sources [0 ].src = ' ' ;
209
- this .modalPlayerOptions .sources [0 ].src = ' ' ;
210
- }
217
+ this .clearSrc ();
211
218
return {};
212
219
}
213
220
if (! this .isMatchPosterUrl (options .poster )) {
Original file line number Diff line number Diff line change @@ -129,4 +129,33 @@ describe('VideoPlayer.vue', () => {
129
129
const res9 = wrapper . vm . isMatchPosterUrl ( 'http://127.0.0.0:8080/a.png' ) ;
130
130
expect ( res9 ) . toBeTruthy ( ) ;
131
131
} ) ;
132
+ it ( 'clear src when url is empty' , async ( done ) => {
133
+ const url = 'http://1.fakeurlAA.flv' ;
134
+ wrapper = mount ( SmVideoPlayer , {
135
+ localVue,
136
+ propsData : {
137
+ url,
138
+ isFullscreen : false ,
139
+ ratio : 'origin' ,
140
+ options : {
141
+ muted : true ,
142
+ loop : false ,
143
+ popupToPlay : true ,
144
+ autoplay : false ,
145
+ controlBar : true ,
146
+ poster : ''
147
+ }
148
+ } ,
149
+ attachToDocument : 'body'
150
+ } ) ;
151
+ expect ( wrapper . find ( '.sm-component-video-player' ) . exists ( ) ) . toBe ( true ) ;
152
+ expect ( wrapper . vm . playerOptions . sources [ 0 ] . src ) . toBe ( url ) ;
153
+ expect ( wrapper . vm . modalPlayerOptions . sources [ 0 ] . src ) . toBe ( url ) ;
154
+ await wrapper . setProps ( {
155
+ url : ''
156
+ } ) ;
157
+ expect ( wrapper . vm . playerOptions . sources [ 0 ] . src ) . toBe ( '' ) ;
158
+ expect ( wrapper . vm . modalPlayerOptions . sources [ 0 ] . src ) . toBe ( '' ) ;
159
+ done ( ) ;
160
+ } ) ;
132
161
} ) ;
You can’t perform that action at this time.
0 commit comments