2

我注意到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包含视图控制器

#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 和其他播放器都很好。

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

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

4

1 回答 1

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];
于 2013-07-25T06:58:34.770 回答