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)

Most upvoted comments

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: Screenshot at Mar 15 11-37-13

And this is how it looks like for a failed mp3: Screenshot at Mar 15 11-36-55

Also when logging the android logs with logcat and adding some comments in capacitorโ€™s WebViewLocalServer.java in shouldInterceptRequest and handleLocalRequest I see the following: Screenshot at Mar 15 14-38-22

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_7 and u1b_8 was working in the last screenshot. However u1b_5 and u1b_6 failed.