@@ -145,12 +145,8 @@ export class ElementsPartsComponent implements OnInit {
145145 // 3.5 的 TS 版本无法使用 ?.
146146 // @ts -ignore
147147 const data = res . type ? res : res . resp ? res . resp . data : undefined ;
148- // 某些后端会把状态放在 data 中,兜底读取
149- // @ts -ignore
150- const status = ( res && res . status ) || ( data && data . status ) ;
151148
152- // 只要拿到 src 就先构建分片并播放,后续是否 still running 由后台继续处理
153- if ( data && data . src ) {
149+ if ( data && data . src && res . status !== 'running' ) {
154150 section = {
155151 id : this . id ,
156152 account : data . account ,
@@ -180,7 +176,7 @@ export class ElementsPartsComponent implements OnInit {
180176
181177 return false ;
182178 }
183- } else if ( status === 'running' ) {
179+ } else if ( res && res . status === 'running' ) {
184180 this . alertShown = true ;
185181 await this . delay ( 3000 ) ;
186182 return await this . fetchSection ( item , sessionId , isFirstPush ) ;
@@ -202,19 +198,19 @@ export class ElementsPartsComponent implements OnInit {
202198 async handlePartFileReplay ( file : IFile [ ] , sessionId : string ) {
203199 let isFirstPush = true ;
204200
205- if ( ! file || file . length === 0 ) {
206- return ;
207- }
201+ for ( const item of file ) {
202+ // 先拿第一个保证有东西可以播出来
203+ isFirstPush = await this . fetchSection ( file [ 0 ] , sessionId , isFirstPush ) ;
208204
209- // 先请求第一个,保证尽快有可播放的内容
210- isFirstPush = await this . fetchSection ( file [ 0 ] , sessionId , isFirstPush ) ;
205+ // 其他的放到异步任务中
206+ Promise . resolve ( ) . then ( async ( ) => {
207+ for ( const item of file . slice ( 1 ) ) {
208+ await this . fetchSection ( item , sessionId , isFirstPush ) ;
209+ }
210+ } )
211211
212- // 其余分片放到后台依次请求,避免与首个分片并发拥塞
213- Promise . resolve ( ) . then ( async ( ) => {
214- for ( const rest of file . slice ( 1 ) ) {
215- await this . fetchSection ( rest , sessionId , false ) ;
216- }
217- } ) ;
212+ isFirstPush = await this . fetchSection ( item , sessionId , isFirstPush ) ;
213+ }
218214 }
219215
220216 /**
0 commit comments