ios - 在 native iOS 应用程序中启用自动播放

标签 ios html video uiwebview autoplay

我正在尝试在我正在开发的原生 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/

相关文章:

android - 具有过渡效果的图像到视频转换

ios - 无法读取崩溃日志

ios - 在 `shouldSendPushNotifications`之前访问Sinch PushPayload

javascript - 对 Angular 滚动div

javascript - 如何使用以对象为目标的 jquery 在特定元素之后附加元素?

unity3d - Unity Video脚本未播放声音

ios - 根据 Swift 3 中 UITableView 中的单元格选择删除文件

ios - 由于 '_alwaysRunsAtForegroundPriority',Ionic 应用程序在 iOS 12.2 上崩溃

internet-explorer - IE 的 Firefox 插件

android - 在 ionic cordova 中将视频文件存储在外部 SD 卡上