【问题标题】:UIWebview video playing crash - Limited to jw player in HTMLUIWebview 视频播放崩溃 - 仅限于 HTML 中的 jw 播放器
【发布时间】:2013-07-21 07:48:28
【问题描述】:

我今天注意到UIWebview 的奇怪行为。

当您在模态视图中打开 Uiwebview 并播放视频时。完整的视频播放完毕后,我们dismissuiwebview 再次调用它,我们就会崩溃。

这里要注意的有趣一点是,这种行为只存在于iPad 中,并且在iPhone 中可以正常工作。

在调试和启用它指向的僵尸时

[MPTransportButton _isChargeEnabled]: message sent to deallocated instance 0x7530930.

调用者:

#import "POCViewController.h"
#import "POCWebViewController.h"

@interface POCViewController ()

@end

@implementation POCViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)displayWebview:(id)sender {
    POCWebViewController *objPOCWebViewController = [[POCWebViewController alloc]init];
    [self presentViewController:objPOCWebViewController animated:YES completion:nil];
    [objPOCWebViewController release];
}
@end

包含视图控制器的UIWebview

#import "POCWebViewController.h"

@interface POCWebViewController ()

@end

@implementation POCWebViewController
@synthesize webview;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    NSURL *usl = [NSURL URLWithString:@"Any Youtube url"];
    NSURLRequest *urlReq = [NSURLRequest requestWithURL:usl];
    [webview loadRequest:urlReq];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    if(webview != nil)
    [webview release], webview = nil;
    [super dealloc];
}
- (IBAction)dismissTapped:(id)sender {
    [self dismissViewControllerAnimated:NO completion:nil];
}
@end

知道我哪里出错了吗?

编辑 1:在玩过代码后,我发现缺陷仅限于 HTML 中使用的“jw-player”,即 flash 和其他播放器都很好。

您可以尝试使用此链接http://www.longtailvideo.com/jw-player/ 打开同一个 POC。这使用了一个 jw 播放器。

播放完整视频时,如果您关闭包含uiwebviewview controller 并再次呈现它,则会导致崩溃。

【问题讨论】:

  • 我想向您推荐使用 YouTubeVideoPlayer github.com/surajwebo/YouTubeVideoPlayer 。我用它。它工作正常。
  • 不仅仅是播放 youtube 视频,任何带有嵌入视频的 HTML 的行为都相同。

标签: ios objective-c xcode ipad uiwebview


【解决方案1】:

使用以下代码在网络视图中播放视频,它对我的​​ youtube 和 vimeo 视频都有效,如果您有任何疑问,请告诉我。

NSString *youTubeID = @"YOUR YOUTUBE ID";
 NSString *embedHTML =[NSString stringWithFormat:@"\
                          <html><head>\
                          <style type=\"text/css\">\
                          body {\
                          background-color: #666666;\
                          padding:%f %f %f %f;\
                          color: blue;\
                          }\
                          </style>\
                          </head><body style=\"margin:0\">\
                          <iframe height=\"%f\" width=\"%f\" title=\"YouTube Video\" class=\"youtube-player\" src=\"http://www.youtube.com/embed/%@\" ></iframe>\
                          </body></html>",paddingTop,paddingRight,paddingBottom,paddingLeft,videoHeight,videoWidth,youTubeID];
[self.webView loadHTMLString:embedHTML baseURL:nil];

【讨论】:

    猜你喜欢
    • 2016-07-09
    • 2014-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-13
    • 1970-01-01
    相关资源
    最近更新 更多