我正在尝试在我正在开发的原生 iOS 应用中启用视频自动播放。我的公司将在明年开发一款成熟的应用程序,但我的任务是构建一个快速原型(prototype)。这个原型(prototype)的目的是为我们提供一个快速工具来使用自动播放功能,该功能将通过 UIWebView 提供。 .
只是为了多画一点图画。我们当前的网站 UX 最好具有自动播放功能,我们的许多用户都要求在我们的网站移动版本上使用此功能。目前我们确实为移动设备提供了一个略有不同的网站,但您可能知道 Apple(由于数据问题)已通过 JS/HTML5 等禁用自动播放。这就是我们想要在不久的将来。
所以我是 Objective-C 和 iOS 开发的新手,但在阅读了大约半天的 Apple 开发人员文档后,我已经设法将我们的网站加载到 UIWebView 中。然后我设置 mediaPlaybackRequiresUserAction = NO
。但是,我没有在 iOS 模拟器中看到自动播放功能。
在此处查看更多详细信息:
mediaPlaybackRequiresUserAction A Boolean value that determines whether HTML5 videos can play automatically or require the user to start playing them.
@property(nonatomic) BOOL mediaPlaybackRequiresUserAction Discussion The default value on both iPad and iPhone is YES.
Availability Available in iOS 4.0 and later. Declared In UIWebView.h
这是我的 ViewController.h 的内容:
#import <UIKit/UIKit.h>
@interface myCompanyViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@end
这是我的 ViewController.m:
#import "myCompanyViewController.h"
@interface myCompanyViewController ()
@end
@implementation myCompanyViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *fullURL = @"http://www.mycompany.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];
_webView.allowsInlineMediaPlayback = YES;
_webView.mediaPlaybackRequiresUserAction = NO;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
那我错过了什么?感谢您提供的任何帮助和建议。
最佳答案
在 stackoverflow 上找到这个:
“Apple 已决定通过脚本和属性实现禁用 iOS 设备上的自动播放视频。
在 Safari 中,在 iOS(适用于所有设备,包括 iPad)上,用户可能使用蜂窝网络并按数据单位收费,预加载和自动播放被禁用。在用户启动之前不会加载数据。”- Apple 文档。
Apple 的保姆州!
关于ios - 在 native iOS 应用程序中启用自动播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14047185/