UIWebview视频播放崩溃 - 仅限于HTML中的jw播放器

时间:2013-07-22 14:16:47

标签: ios objective-c xcode ipad uiwebview

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

在模态视图中打开Uiwebview&播放视频。播放完整的视频后,我们dismiss uiwebview并再次调用它,我们就会崩溃。

这里有趣的一点是,此行为仅出现在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包含viewcontroller

#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-player。

播放完整视频时,如果您关闭包含view controller& {}的uiwebview再次呈现它会导致崩溃。

1 个答案:

答案 0 :(得分:0)

使用以下代码在网络视图中播放视频,其中包含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];