Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: HTML5 video element refuses to play on all devices after update although it works on browser versions of Safari and Chrome #6622

Closed
simaxme opened this issue May 29, 2023 · 15 comments
Labels
needs reproduction needs reproducible example to illustrate the issue

Comments

@simaxme
Copy link

simaxme commented May 29, 2023

Bug Report

Capacitor Version

馃拪 Capacitor Doctor 馃拪

Latest Dependencies:

  @capacitor/cli: 5.0.4
  @capacitor/core: 5.0.4
  @capacitor/android: 5.0.4
  @capacitor/ios: 5.0.4

Installed Dependencies:

  @capacitor/cli: 5.0.4
  @capacitor/core: 5.0.4
  @capacitor/android: 5.0.4
  @capacitor/ios: 5.0.4

Platform(s)

  • iOS / iPadOS

Current Behavior

HTML5 Video-Element from assets folder or blob url refuses to play.

Expected Behavior

HTML5 Video-Element should play normally

Code Reproduction

      <video [muted]="true"
             loop="loop"
             muted
             playsinline
             [attr.webkit-playsinline]="'webkit-playsinline'"
             [controls]="false"
             #video
             src="{{content}}"
      ></video>

Here, every possible attribute is used for making the video play automatically and in a loop. This does completely work in the Safari and Chrome browser.

Other Technical Details

This issue is only happening due to using a local url or blob url. In the given example, content does refer to the simple string "/assets/quickstart/example.mp4". The safari dev-tools show that the video is being loaded in different chunks:
image

In chrome dev-tools simply many errors are sent while trying to load the mp4:
image

Here, two of the video elements are loaded in chunks, but neither of them does play. When manually activating the controls and pressing the play button, the timeline on the button is very bugged and always extends the duration of the video.
IMG_4C0CB494F4DA-1

One interesting fact: Videos do play in this way as soon as they refer to a complete existing HTTP-URL from an other server. It looks like it has to do something with the capacitor:// url.

Local addresses are working normally when using images. Only video tags are not loading.

npm --version output:

node --version output:

pod --version output (iOS issues only):

Additional Context

This did happen at first after updating to Capacitor v5 from v4. It seems some mechanics changed here.

At least when using the local urls, it has to do something with the range requests: #1343

Hope someone can help me 馃槗

@ionitron-bot ionitron-bot bot added the triage label May 29, 2023
@JaHollTV
Copy link

Hey there,
i have same problem with a simmilar usecase. Only with iOS

@simaxme simaxme changed the title bug: HTML5 video element refuses to play on iOS and iPadOS after update although it works on native Safari bug: HTML5 video element refuses to play on all devices after update although it works on native Safari May 29, 2023
@simaxme simaxme changed the title bug: HTML5 video element refuses to play on all devices after update although it works on native Safari bug: HTML5 video element refuses to play on all devices after update although it works on native Safari and Chrome May 29, 2023
@simaxme
Copy link
Author

simaxme commented May 29, 2023

Hello, i have to give one small update: Android now works by using a workaround

  • i was able to manually fetch the video and provide the video tag with a reference to the corresponding blob. This did work perfectly.
  • I found this solution from the issue: Android range requests聽#5956

For the next person facing this: We circumvent the issue by downloading the media file without streaming (using Angular HTTP service, fetch() would probably also work) and map it to a resource URL (URL.createObjectURL(blob)) that we point our media elements to.

iOS still does not work with this solution. Although i have preloaded the video, safari keeps trying to load the blob in small parts:
image

@simaxme
Copy link
Author

simaxme commented May 29, 2023

Next comment: I also got it working in iOS and iPadOS:

While createObjectURL() causes Safari trying to load the video in chunks, dataURLs are not causing this weird issue and are working perfectly when using videos. The only downside on this part is the data limitation of around 2Mb.

In our application this is not important as the videos reach a maximum of 3sec playtime.

Although for me this issue is fixed, i will keep it open as these described things are complete workarounds that will not work in any case.

@jcesarmobile jcesarmobile added the needs reproduction needs reproducible example to illustrate the issue label May 30, 2023
@ionitron-bot ionitron-bot bot removed the triage label May 30, 2023
@Ionitron
Copy link
Collaborator

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks!
Ionitron 馃挋

@Ionitron Ionitron added the needs reply needs reply from the user label May 30, 2023
@jansgescheit
Copy link
Contributor

jansgescheit commented Jun 5, 2023

I am running in similar failure on Capacitor 4!

馃拪   Capacitor Doctor  馃拪 

Latest Dependencies:

  @capacitor/cli: 5.0.4
  @capacitor/core: 5.0.4
  @capacitor/android: 5.0.4
  @capacitor/ios: 5.0.4

Installed Dependencies:

  @capacitor/core: 4.8.0
  @capacitor/cli: 4.8.0
  @capacitor/ios: 4.8.0
  @capacitor/android: 4.8.0

[success] iOS looking great! 馃憣

In my case i download the Videos with angular http.get as a blob and create with URL.createObjectURL the object url. This works fine on a desktop browsers and sometimes also on native! But i discovered problems on iOS / iPadOS.

The created Object URL's are prefixt with blob:capacitor://localhost/. In this case the HTMLVideo Player shows a blank Video.

if i remove capacitor:// from URL to blob:localhost/6310f486-da40-423d-95b9-c96253a00555 the video plays as expected.

@Ionitron Ionitron removed the needs reply needs reply from the user label Jun 5, 2023
@jcesarmobile jcesarmobile added the needs reply needs reply from the user label Jun 5, 2023
@Miguelmcanabal
Copy link

Im managing the same issue on Capacitor 5 in a 10th gen iPad with iOS 16.4.

   Capacitor Doctor   

Latest Dependencies:

  @capacitor/cli: 5.0.4
  @capacitor/core: 5.0.4
  @capacitor/android: 5.0.4
  @capacitor/ios: 5.0.4

Installed Dependencies:

  @capacitor/cli: 5.0.4
  @capacitor/core: 5.0.4
  @capacitor/ios: 5.0.4
  @capacitor/android: 5.0.4

I cannot reproduce videos from Angular assets, video player fails and it crashes the iPad gallery! After trying to play a video, if i try to open a video in iOS gallery, it wont play either. Its a weird behaviour to be honest.

@Ionitron Ionitron removed the needs reply needs reply from the user label Jun 8, 2023
@jcesarmobile jcesarmobile added the needs reply needs reply from the user label Jun 8, 2023
@digaus
Copy link
Contributor

digaus commented Jun 22, 2023

Same issue here. Workaround is to use the Filesystem and Uri but thats not a great solution.

I could provide a demo project if needed?

@Ionitron Ionitron removed the needs reply needs reply from the user label Jun 22, 2023
@jansgescheit
Copy link
Contributor

Same issue here. Workaround is to use the Filesystem and Uri but thats not a great solution.

I could provide a demo project if needed?

I had also tried that way, but that had not worked either. Would be nice if you could share a few lines of code.

@digaus
Copy link
Contributor

digaus commented Jun 22, 2023

Same issue here. Workaround is to use the Filesystem and Uri but thats not a great solution.
I could provide a demo project if needed?

I had also tried that way, but that had not worked either. Would be nice if you could share a few lines of code.

                const url: string = './assets/getreide.mp4' 
                const path: string = 'videos/getreide.mp4';
                const dir: ReadFileResult = await Filesystem.readFile({
                    path,
                    directory: Directory.Data,
                }).catch((err: unknown) => { console.error(err); return null; });
                if (!dir) {
                    const v: Blob = await fetch(url).then((val: Response) => val.blob());
                    await writeBlob({
                        path,
                        directory: Directory.Data,
                        blob: v,
                        fast_mode: true,
                        recursive: true,
                    });
                    
                }
                const directory: GetUriResult = await Filesystem.getUri({
                    path,
                    directory: Directory.Data,
                }).catch((err: unknown) => { console.error(err); return null; });
                if (directory) {
                    const fileSrc: string = Capacitor.convertFileSrc(`${ directory.uri }?v=${Date.now()}`);
                    return this.myDomSanitizer.bypassSecurityTrustResourceUrl(fileSrc);
                }

writeBlob is imported from capacitor-blob-writer

I needed to make sure to only write the blob once, otherwise it stops working after a while (only restarting iPhone fixed that)

@jcesarmobile jcesarmobile added needs reproduction needs reproducible example to illustrate the issue and removed needs reproduction needs reproducible example to illustrate the issue labels Jun 26, 2023
@Ionitron
Copy link
Collaborator

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks!
Ionitron 馃挋

@Ionitron Ionitron added the needs reply needs reply from the user label Jun 26, 2023
@Ionitron
Copy link
Collaborator

It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot.

Have a great day!
Ionitron 馃挋

@Ionitron Ionitron removed the needs reply needs reply from the user label Jul 12, 2023
@simaxme
Copy link
Author

simaxme commented Jul 12, 2023

Wow, you have the best bot ever . This Issue is real and needs to be adressed!

@jansgescheit
Copy link
Contributor

Wow, you have the best bot ever . This Issue is real and needs to be adressed!

I thought so too

@simaxme
Copy link
Author

simaxme commented Jul 12, 2023

If there is no response in this week, i will open a new issue with the same problem. The problem is obvious and needs to be adressed. It would be nice if someone could respond to avoid this unnecessary work.

@simaxme simaxme changed the title bug: HTML5 video element refuses to play on all devices after update although it works on native Safari and Chrome bug: HTML5 video element refuses to play on all devices after update although it works on browser versions of Safari and Chrome Jul 12, 2023
@ionitron-bot
Copy link

ionitron-bot bot commented Aug 11, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Aug 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs reproduction needs reproducible example to illustrate the issue
Projects
None yet
Development

No branches or pull requests

7 participants