2011-08-02 2 views
2

내 UIWebView 컨트롤에서 dailymotion 및 youtube 비디오를 재생하고 싶습니다. 그리고 난 다음과 같은 임베디드 html 코드를 사용하여 잘 작동합니다. 그러나 장치가 회전 중일 때 그에 따라 재설정되지 않으며 다음 코드를 다시 호출하면 처음부터 비디오가 재생됩니다.임베디드 비디오를 여러 방향으로 재생 중입니까?

NSString* embedHTML = @"<html><head><style>body {\"background-color:transparent;color:black;\"}</style></head><body style=\"margin:0\"><embed id=\"yt\" src=\"%@\"type=\"application/x-shockwave-flash\"width=\"%.0f\" height=\"%.0f\"></embed></body></html>"; 
    NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height]; 

장치 회전에 따라 내보기를 재설정하고 다시 시작하지 않고 계속 재생하는 솔루션은 무엇입니까?

편집 : 재생 모드에서 동영상의 방향이 완벽하게 바뀌고 있습니다. 일단 내가 그것을 중지하고보기를 회전하려고하면 webview의 내용이 회전하지 않습니다. 그리고 저는 그것의 해결책을 찾고 있습니다.

답변

0

나는이를위한 튜토리얼을 만들었고, 인터페이스가 변경되는 곳에서도 작업을 수행했다.

여기 구현 파일이 있습니다. 다만, 컨트롤러에 붙여 넣기 URL을 넣어이 코드 여기

#import "TestVideoViewController.h" 
#import "UICommonUtils.h" 

@implementation TestVideoViewController 
@synthesize TestVideoView; 


- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
    //sleep(10.0); 
    [busyLoadingView hide:YES]; 
    //bShow = NO; 
} 

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 
{ 
    //sleep(10.0); 
    [busyLoadingView hide:YES]; 
    //bShow = NO; 
} 

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{ 
    //bShow = YES; 
    //[busyLoadingView showWhileExecuting:@selector(showCursor:) onTarget:self withObject:nil animated:YES]; 

    //[busyLoadingView show:YES]; 
    return YES; 
} 

- (void)webViewDidStartLoad:(UIWebView *)webView 
{ 
    [busyLoadingView show:YES]; 
} 

-(void)viewWillDisappear:(BOOL)animated 
{ 
    [self embedVideo1:@"PASS HERE URL1" andVideo2:@"PASS HERE URL2" frame:self.view.frame]; 
} 

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
     [super viewDidLoad]; 

    CGRect rectFrame = [UIScreen mainScreen].applicationFrame; 

    self.view.frame = rectFrame; 
    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 
    self.view.autoresizesSubviews = YES; 
    //TestVideoView.scalesPageToFit = YES; 
//TestVideoView.backgroundColor = [UIColor clearColor]; 

    busyLoadingView = [[MBProgressHUD alloc] initWithView:self.view]; 


    // Add HUD to screen 
    [self.view addSubview:busyLoadingView]; 

    busyLoadingView.labelText = @"Loading..."; 

    [self embedVideo1:@"PASS HERE URL1" andVideo2:@"PASS HERE URL2" frame:self.view.frame]; 

    //self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    //self.view.autoresizesSubviews = YES; 

} 

- (void)embedVideo1:(NSString*)url1 andVideo2:(NSString*)url2 frame:(CGRect)frame { 
     float videoWidth = 748.0; 
    float videoHeight = 341.0; 
    //int marginLeft = 10; 
    //int marginTop = 10; 

    if ([UICommonUtils isiPad]){ 
     videoWidth = 748.0; 
     videoHeight = 341.0; 
     //marginLeft = (int)(frame.size.width - videoWidth) /2; 
     //marginTop = 10; 
    } else { 
     videoWidth = 300.0; 
     videoHeight = 160.0; 
     //marginLeft = 10; 
     //marginTop = 10; 
    } 

    NSString* embedHTML = @" \ 
     <html><head> \ 
    <style type=\"text/css\"> \ 
    .style11 { \ 
    font-family:Arial,Helvetica,sans-serif; \ 
    font-weight:bold; \ 
    font-size:16; \ 
    } \ 
    .style12 { \ 
    width: \"%0.0f\"; \ 
    height=\"%0.0f\" \ 
    align = center; \ 
    } \ 
    .style21 { \ 
    font-family:Arial,Helvetica,sans-serif; \ 
    font-weight:bold; \ 
    font-size:16; \ 
    } \ 
    .style22 { \ 
    width: \"%0.0f\"; \ 
    height=\"%0.0f\" \ 
    align = center; \ 
    } \ 
    body {\ 
    background-color: transparent; \ 
    color: black; \ 
    } \ 
    </style> \ 
    </head><body> \ 
    <table> \ 
    <tr><td><span class=\"style11\">1) Collecting and Editing Leads</span></td></tr> \ 
    <tr><td height=20></td></tr> \ 
    <tr><td class=\"style12\"> \ 
    <embed id=\"yt1\" src=\"%@\" type=\"application/x-shockwave-flash\" width=\"%0.0f\" height=\"%0.0f\"> \ 
     </embed> \ 
    </td></tr> \ 
    <tr height=20></tr> \ 
    <tr><td><span class=\"style21\">2) Accessing Leads Online</span></td></tr> \ 
    <tr><td height=20></td></tr> \ 
    <tr><td class=\"style22\"> \ 
    <embed id=\"yt2\" src=\"%@\" type=\"application/x-shockwave-flash\" width=\"%0.0f\" height=\"%0.0f\"> \ 
    </embed> \ 
    </td></tr> \ 
    </table> \ 
     </body></html>"; 
    NSString* html = [NSString stringWithFormat:embedHTML, videoWidth, videoHeight, videoWidth, videoHeight, url1, videoWidth, videoHeight, url2, \ 
        videoWidth, videoHeight]; 
    //NSString* html = [NSString stringWithFormat:embedHTML, videoWidth, videoHeight, videoWidth, videoHeight, url1, videoWidth-20, videoHeight, url2, \ 
    //    videoWidth-20, videoHeight]; 
    /* 
    if(videoView == nil) { 
     videoView = [[UIWebView alloc] initWithFrame:frame]; 
     [self.view addSubview:videoView]; 
    } */ 
    //[TestVideoView loadHTMLString:html baseURL:nil]; 
    [(UIWebView *)self.view loadHTMLString:html baseURL:nil]; 
} 


// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    //return (interfaceOrientation == UIInterfaceOrientationPortrait); 
//return YES; 
    if([UICommonUtils isiPad]) return YES; 
    else return NO; 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    //CGRect rectFrame = [UIScreen mainScreen].applicationFrame; 

    //self.view.frame = rectFrame; 
    //NSLog([NSString stringWithFormat:@"origin x: %f origin y: %f width: %f height: %f", rectFrame.origin.x, 
    //  rectFrame.origin.y, rectFrame.size.width, rectFrame.size.height]); 

    //TestVideoView.frame = CGRectMake(rectFrame.origin.x, rectFrame.origin.y, rectFrame.size.height, rectFrame.size.width);  
} 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
} 


@end 

을 시도 복사하면이 당신을 도움의 ViewController

#import <UIKit/UIKit.h> 
#import "MBProgressHUD.h" 


@interface TestVideoViewController : UIViewController<UIWebViewDelegate>{ 
    UIWebView *TestVideoView; 
    MBProgressHUD *busyLoadingView; 
    BOOL bShow; 
} 

@property (nonatomic, retain) IBOutlet UIWebView *TestVideoView; 

- (void)embedVideo1:(NSString*)url1 andVideo2:(NSString*)url2 frame:(CGRect)frame; 

@end 

희망의 헤더 파일입니다.

도움이 더 필요하시면 알려 주시기 바랍니다. 편집이

: 가이 코드는 대부분의 아마 실 거예요 shockwave- 플래시 플레이어에게 나던 시뮬레이터로 시뮬레이터에서 제대로 작동

+0

컴파일러는 # import에 대한 오류를 보여줍니다 "UICommonUtils.h". #import "UICommonUtils.h"가 누락되었습니다. 친절히 클래스에 대한 참조를 알려주십시오. –

+0

아니요 기기가 iphone인지 ipad인지 확인하는 것은 제 맞춤 수업이었습니다. 지금 당장이나 ipad 장치를 가지고 있다면 ipad 장치에서 재생하는 것을 고려해 볼 수 있습니다.이 경우에는 장치 유형을 확인하지 않아도됩니다. 따라서 UICommonUtils 클래스에 대한 조건부 검사 및 참조를 제거 할 수 있습니다. –

+0

내 대답의 편집 섹션을 확인하십시오. UICommonUtils 클래스 오류와 관련이 없지만 중요한 점을 추가했습니다. –

관련 문제