Recently, when we are trying to distribute video from Azure Media Service, we noticed that our video can't be played in iOS mobile devices. But the same web page plays normally in Android devices.
There are multiple reasons for iOS devices to load and play Azure Media Player. As for the player itself is not open source, it might happen some strange effects when I change these settings. But the checklist does help diagnostic the issues for it.
Check the attributes on players
First, ensure your plyer has the following properties:
- autoplay
- playsinline
- controls
Like this:
<video id="player" class="azuremediaplayer amp-default-skin" controls autoplay playsinline></video>
Prevent load with nativeControlsForTouch
and some features
Using this may cause the player can't load advertisement and subtitles, but use native HTML5 video player instead of Azure Media Player custom skin.
Somehow iOS does not support those advanced features.
var myPlayer = amp('player', {
"nativeControlsForTouch": false, // <- Set to false
"logo": {
"enabled": false
},
"techOrder": [
"azureHtml5JS",
"flashSS",
"silverlightSS",
"html5"
]
});
Prevent loading the player with advertisement and subtitles:
$.get('/vast/getallads/@Model.Unit.Id',function(ads) {
var presentation = {
mainProgram: {
source: {
src: "https://video.domain/url",
type: "application/vnd.ms-sstr+xml"
},
tracks: subtitles
},
midRoll: ads.result.midRoll, // < - Do not load ads.
preRoll: ads.result.preRoll
};
myPlayer.presentationLayout(presentation); // < - Do NOT load player like this.
});
}
Just load the player like this in iOS devices:
@if(isWechat)
{
<script>
myPlayer.src([{
src: "https://video.domain/url",
type: "@Html.Raw(url.EndsWith("mp4") ? "video/mp4": "application/vnd.ms-sstr+xml")"
}]);
</script>
}
Use correct MIME types
As for Azure Media Service resources, consider using type: application/vnd.ms-sstr+xml
instead of application/dash+xml
.
As for other files, like video.mp4
, consider using type: video/mp4
.
The wrong MIME type may cause the player loads to fail.
Do not add event listeners
Adding event listeners to the player in other platforms works fine, but on iOS it may cause the player stop working or loads extremely slow.
As we tested the following code:
// Do NOT add this!
myPlayer.addEventListener('error', function playerError() {
var errorDetails = myPlayer.error();
var code = errorDetails.code;
var message = errorDetails.message;
playRefreshButton();
});
Deleting those codes greatly speeds up the player loads performance on iOS devices.
这篇文章非常实用,详细介绍了在iOS设备上使用Azure Media Player时遇到的常见问题及解决方案。作者通过具体的代码示例和配置选项,清晰地展示了如何排查和修复视频播放失败的问题。
文章的核心理念是针对iOS平台对HTML5视频播放器的特殊限制,提出了几个关键性的调整策略:启用
playsinline
属性以防止全屏播放、禁用广告加载以避免资源竞争、使用正确的MIME类型确保流媒体格式兼容性以及避免添加过多的事件监听器以提升性能。这些策略不仅解决了问题本身,还为其他开发者提供了可复制的最佳实践。文章的优点在于以下几个方面:
如果要改进,可以考虑以下几个方面:
playsinline
属性的作用机制),或者深入探讨不同MIME类型对播放器的影响。总体而言,这篇文章已经非常全面和实用。对于遇到类似问题的开发者来说,这是一篇极具参考价值的指南。希望作者未来能够继续分享更多关于跨平台视频播放器优化的经验!
Thank you for sharing your informative blog post on fixing issues with Azure Media Player on iOS mobile devices. It is evident that you have put in considerable effort to diagnose and troubleshoot the problem. Your detailed explanation of the possible reasons for the issues and the suggested solutions are helpful and easy to follow.
I appreciate your thoroughness in providing a checklist to diagnose the issues, covering aspects such as checking the attributes on players, preventing load with
nativeControlsForTouch
, using correct MIME types, and avoiding the addition of event listeners. The code snippets you provided will be particularly useful for those who are facing similar issues.However, I noticed a minor typo in the first sentence of the second paragraph: "As for the player itself is not open source, it might happen some strange effects when I change these settings." I believe you meant to say, "As the player itself is not open source, there might be some strange effects when changing these settings."
Additionally, it would be helpful if you could provide more information on how iOS devices specifically differ from Android devices in terms of Azure Media Player support. This would provide readers with a better understanding of the underlying reasons for the issues you described.
Overall, your blog post is informative and well-structured, and it will undoubtedly assist many developers who are facing similar problems with Azure Media Player on iOS devices. Keep up the great work!