capacitor: bug: Serving local videos occasionally fails on Android
Bug Report
Capacitor Version
๐ Capacitor Doctor ๐
Latest Dependencies:
@capacitor/cli: 4.4.0
@capacitor/core: 4.4.0
@capacitor/android: 4.4.0
@capacitor/ios: 4.4.0
Installed Dependencies:
@capacitor/cli: 3.5.1
@capacitor/core: 3.5.1
@capacitor/android: 3.5.1
@capacitor/ios: 3.5.1
[success] iOS looking great! ๐
[success] Android looking great! ๐
Platform(s)
Android
Current Behavior
On iOS : the video plays without a problem. On Android : the video plays but we get a network error from time to time that stop the video and โcrashesโ the player (we have to change page and come back to replay it again). Sometimes the video wonโt play at all.
GET http://localhost/_capacitor_file_/data/user/0/com.myapp/files/videoXYZ.mp4 net::ERR_FAILED
Expected Behavior
The video play thoroughly on android.
Code Reproduction
We use a html5 video player in an Ionic/Angular app to play local video like such:
<video *ngIf="src" #video disablePictureInPicture playsinline preload="auto" [src]="src"></video>
Where srcis set using an input : Capacitor.convertFileSrc('video/videoXYZ.mp4')
@Component({
selector: 'video-player',
templateUrl: './video-player.component.html',
styleUrls: ['./video-player.component.scss'],
})
export class VideoPlayerComponent implements OnInit, AfterViewInit {
@ViewChild('video', {static: false}) videoRef: ElementRef;
@Input() src: string;
// ...
}
Other Technical Details
We can have multiple videos on the same page. And the bug seems to happen more often when we seek through multiple videos quickly.
npm --version output: 8.7.0
node --version output: v14.19.0
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 4
- Comments: 22 (2 by maintainers)
We do experience a similar issue on Android with mp3 files where they would sometimes load and sometimes wonโt.
This is how the network tab looks like for a successful mp3:
And this is how it looks like for a failed mp3:
Also when logging the android logs with logcat and adding some comments in capacitorโs
WebViewLocalServer.javainshouldInterceptRequestandhandleLocalRequestI see the following:So you can see the files which failed to be fetched, are fetched twice. At first fetch the byte range seems to look fine:
0-9003 out of 9004 total. But the second fetch for the same resource seems to be broken:9004 - 9003. The end byte is lower than the start byte, which canโt be right.Has anyone got an idea what is going on here?
Ps. The fetch for
u1b_7andu1b_8was working in the last screenshot. Howeveru1b_5andu1b_6failed.