2013-07-22 26 views
2

到JW球員,我注意到今天UIWebview的怪異行爲。UIWebView的視頻播放崩潰 - 有限的HTML

當您在模式視圖中打開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',即其他玩家沒有問題。

您可以嘗試使用此鏈接打開相同的POC http://www.longtailvideo.com/jw-player/。這使用一個jw球員。

當完整的視頻播放,如果您關閉view controller包含uiwebview &目前它再次,它會導致崩潰。

+0

我想推薦您使用YouTubeVideoPlayer https://github.com/surajwebo/YouTubeVideoPlayer。我用它。它工作正常。 – stosha

+0

它不只是播放YouTube視頻,但有一個嵌入式視頻的任何HTML的表現一樣。 – footyapps27

回答

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]; 
+0

已編輯我的問題。它僅限於'jw-player'。 – footyapps27