WebM is a popular video format that is often used on the web because of its efficient compression and high-quality playback. However, iPhone and other iOS devices do not natively support WebM files.
There are several ways to work around this limitation:
1. Use a Third-Party App
There are several third-party apps available on the App Store that can play WebM files. Some popular ones include:
User
Assistant
In the HTML5 <video> element, the browser will attempt to load the video sources in the order that they are provided. It will check each source to see if it can play it, and will use the first one it supports.
Here's a breakdown of how your provided code works:
<video controls>
<source src="video.mp4" type="video/mp4">
<source src="video.webm" type="video/webm">
Your browser does not support the video tag.
</video>
Ordering of Sources
VLC for Mobile: VLC is a versatile and robust media player that supports a wide range of video formats, including WebM.
PlayerXtreme Media Player: Another comprehensive media player that supports various file formats, including WebM.
2. Convert WebM Videos
If you have WebM videos that you need to play on your iPhone, you can convert them to a format that iOS supports, such as MP4. There are many online and desktop video converters available, such as:
HandBrake: A powerful and open-source video converter.
Online Video Converter: A web-based tool for quick conversions.
3. Use a Different Browser
Some third-party browsers available on the App Store may offer better compatibility with WebM files compared to Safari. Browsers like Chrome or Firefox for iOS might offer better support for WebM playback.
4. Embed Videos in HTML5 Player
If you are a content provider and need to ensure that your videos are accessible on iOS devices, consider embedding your videos using an HTML5 video player that can handle multiple formats. You could provide both WebM and MP4 versions of your video, and the player will serve the appropriate file depending on the viewer’s device:
<video controls>
<source src="video.mp4" type="video/mp4">
<source src="video.webm" type="video/webm">
Your browser does not support the video tag.
</video>
5. Use Cloud Services
Services like Google Drive or Dropbox often have built-in video players that can handle WebM playback, even on iOS devices. Upload your video to the cloud and access it through their app.
By using these methods, you should be able to view WebM videos on your iPhone without any issues.
The browser first encounters the line <source src="video.mp4" type="video/mp4">. It will try to load and play this source first.
If the browser does not support the MP4 format (which is rare since MP4 is widely supported), it will move on to the next source: <source src="video.webm" type="video/webm">.
If neither source is supported, the message "Your browser does not support the video tag." will be displayed.
Common Browser Support
MP4: Supported by most modern browsers, including Safari on iOS, Chrome, Firefox, and Edge.
WebM: Supported by most modern browsers, but not natively supported by Safari on iOS devices.
Recommendations
Since MP4 is more commonly supported across different browsers and platforms, it is a good practice to list it first. This ensures the broadest compatibility:
Ensure your MP4 file is optimized for web playback.
List the WebM source second to provide an option for browsers that support this format and potentially offer better compression.
Example in Best Practice
Here is the code again, ensuring proper quotation marks for the attributes:
<video controls>
<source src="video.mp4" type="video/mp4">
<source src="video.webm" type="video/webm">
Your browser does not support the video tag.
</video>
By following this approach, the browser will attempt to play the MP4 file first, ensuring optimal compatibility with iOS devices among others. If the browser does not support MP4, it will then try to play the WebM file.