2013-03-20 5 views
5

Próbuję wejść w interakcję z załadowaną stroną w UIWebView bez dotykania ekranu. Próbowałem mediaplayback żądać userserms bez powodzenia. Próbowałem również metody dostarczonej here, ale najwyraźniej nie działa w ios 6. Próbuję załadować adres URL this i sprawić, aby odtwarzacz zaczął grać. Czy ktoś wie, jak zrobić to działa ios 6? Każda pomoc jest bardzo doceniana.Czy możliwa jest interakcja z UIWebView bez dotyku?

mój kod

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 


    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1]; 

    NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"]; 
    //storyLink is various form of http://link.brightcove.com/services/player/bcpid1683318714001?bckey=AQ~~,AAAAC59qSJk~,vyxcsD3OtBPHZ2UIrFX2-wdCLTYNyMNn&bclid=1644543007001&bctid=2238216269001 with different bctid=value 

    NSURL *kitcoURL = [NSURL URLWithString:storyLink]; 
    NSURLRequest *requestURL = [NSURLRequest requestWithURL:kitcoURL]; 
    [videoScreen setUserInteractionEnabled:YES]; 
    [videoScreen setMediaPlaybackRequiresUserAction:NO]; 
    [videoScreen loadRequest:requestURL]; 

} 

// metoda nie działa w iOS6

- (UIButton *)findButtonInView:(UIView *)view { 
UIButton *button = nil; 

if ([view isMemberOfClass:[UIButton class]]) { 
return (UIButton *)view; 
} 

if (view.subviews && [view.subviews count] > 0) { 
for (UIView *subview in view.subviews) { 
    button = [self findButtonInView:subview]; 
    if (button) return button; 
} 
} 

return button; 
} 

- (void)webViewDidFinishLoad:(UIWebView *)_webView { 
    UIButton *b = [self findButtonInView:_webView]; 
    [b sendActionsForControlEvents:UIControlEventTouchUpInside]; 
} 

EDIT // wizyjny jest mój UIWebView

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

NSString *urlString = @"http://link.brightcove.com/services/player/bcpid1683318714001?bckey=AQ~~,AAAAC59qSJk~,vyxcsD3OtBPHZ2UIrFX2-wdCLTYNyMNn&bclid=1644543007001&bctid=2238216269001"; 

NSError *error; 
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"bckey=([^&]*)" options:0 error:&error]; 
NSTextCheckingResult *match = [regex firstMatchInString:urlString options:0 range:NSMakeRange(0, urlString.length)]; 
NSString *bckey = [urlString substringWithRange:[match rangeAtIndex:1]]; 

regex = [NSRegularExpression regularExpressionWithPattern:@"bctid=([0-9]*)" options:0 error:&error]; 
match = [regex firstMatchInString:urlString options:0 range:NSMakeRange(0, urlString.length)]; 
NSString *bctid = [urlString substringWithRange:[match rangeAtIndex:1]]; 

NSString *newUrlString = [NSString stringWithFormat:@"http://c.brightcove.com/services/viewer/htmlFederated?&playerKey=%@&videoID=%@", bckey, bctid]; 

[videoScreen loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:newUrlString]]]; 

} 

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
if (!webView.isLoading) 
{ 
    [self checkForVideoReady]; 
} 

} 
// Checking player object for ready. If it ready - starting video. Otherwise waiting 1 second 
- (void)checkForVideoReady 
{ 
    if (![[videoScreen stringByEvaluatingJavaScriptFromString:@"player.ready"] isEqualToString:@"true"]) 
    { 
    [self performSelector:@selector(checkForVideoReady) withObject:nil afterDelay:1]; 
    } 
    else 
    { 
     [videoScreen stringByEvaluatingJavaScriptFromString:@"player.videoPlayer.playButton.element.click();"]; 
    } 
} 
+0

Czy nie jest to dokładnie tym, dla czego służy właściwość 'mediaPlaybackRequiresUserAction' w' UIWebView'? –

+0

MediaPlaybackRequiresUserAction powoduje awarię z powodu nierozpoznanego selektora. Sprawdź edycję. –

+0

Cóż, będziesz musiał użyć 'setMediaPlaybackRequiresUserAction: NO'. videoScreen musi również być "UIWebView". –

Odpowiedz

1

Twoja metoda wyszukiwania przycisku w widoku na podstawie filmów z YouTube 5 w formacie HTML.
Znalazłem obejście Twojego problemu, nie jest eleganckie, ale działa.

Twój link

http://link.brightcove.com/services/player/bcpid1683318714001?bckey=AQ~~,AAAAC59qSJk~,vyxcsD3OtBPHZ2UIrFX2-wdCLTYNyMNn&bclid=1644543007001&bctid=2238216269001

pliki do pobrania strona z obiektów flash. I o ile wiem, nie ma sposobu, aby zacząć grać za pomocą JS lub UIWebView.
Po zbadaniu wniosków Widziałem, że UIWebView zapytanie do innego URL:

http://c.brightcove.com/services/viewer/htmlFederated?&width=966&height=546&flashID=myExperience&bgcolor=%23FFFFFF&playerID=1683318714001&playerKey=AQ~~%2CAAAAC59qSJk~%2CvyxcsD3OtBPHZ2UIrFX2-wdCLTYNyMNn&isVid=true&isUI=true&dynamicStreaming=true&autoStart=true&debuggerID=&videoID=2238216269001&%40videoPlayer=2238216269001&lineupID=1644543007001&startTime=1364279975091&refURL=not%20available&%40videoPlayer=2238216269001

Drugi jest bardziej interesujące, ponieważ mamy dostęp do player zmiennej i uruchomić wideo z użyciem JavaScript.

Musimy więc przekonwertować początkowy adres URL. Wygląda na to, że mamy tylko 2 ważne parametry w URL - bckey i bctid:

NSString *urlString = @"http://link.brightcove.com/services/player/bcpid1683318714001?bckey=AQ~~,AAAAC59qSJk~,vyxcsD3OtBPHZ2UIrFX2-wdCLTYNyMNn&bclid=1644543007001&bctid=2238216269001"; 

NSError *error; 
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"bckey=([^&]*)" options:0 error:&error]; 
NSTextCheckingResult *match = [regex firstMatchInString:urlString options:0 range:NSMakeRange(0, urlString.length)]; 
NSString *bckey = [urlString substringWithRange:[match rangeAtIndex:1]]; 

regex = [NSRegularExpression regularExpressionWithPattern:@"bctid=([0-9]*)" options:0 error:&error]; 
match = [regex firstMatchInString:urlString options:0 range:NSMakeRange(0, urlString.length)]; 
NSString *bctid = [urlString substringWithRange:[match rangeAtIndex:1]]; 

NSString *newUrlString = [NSString stringWithFormat:@"http://c.brightcove.com/services/viewer/htmlFederated?&playerKey=%@&videoID=%@", bckey, bctid]; 

i załadować nowy adres URL

[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:newUrlString]]]; 

Po URL się ładuje mamy dostęp do player obiektu.Ten obiekt może powiedzieć, kiedy film jest gotowy do gry i rozpocząć odtwarzanie

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
    if (!webView.isLoading) 
    { 
     [self checkForVideoReady]; 
    } 

} 
// Checking player object for ready. If it ready - starting video. Otherwise waiting 1 second 
- (void)checkForVideoReady 
{ 
    if (![[_webView stringByEvaluatingJavaScriptFromString:@"player.ready"] isEqualToString:@"true"]) 
    { 
     [self performSelector:@selector(checkForVideoReady) withObject:nil afterDelay:1]; 
    } 
    else 
    { 
     [_webView stringByEvaluatingJavaScriptFromString:@"player.videoPlayer.playButton.element.click();"]; 
    } 
} 

wiem, że to nie jest eleganckie, może ktoś znajdzie sposób, jak go poprawić.
Zapraszam do komentowania.

+0

Dzięki za odpowiedź. Twoja odpowiedź ma sens, ale nie zadziałała, gdy ją zaimplementowałem. Czy jest coś, czego mi brakuje? Sprawdź edycję. –

4

Jeśli chcesz grać tylko piosenkę , jako & po załadowaniu strony internetowej. Następnie należy wywołać funkcję odtwarzania w

`- (void)webViewDidFinishLoad:(UIWebView *)webView { 

    // Do whatever you want here 
    // play song 
}` 

ale upewnij się, że przypisany delegata do WebView jak ten

<UIWebView_object>.delegate = self; 

Spowoduje to automatyczne grać utwory & gdy webview ładunki

Enjoy Programowanie!!

+0

Dzięki za odpowiedź. Nie rozumiem, jak twoja odpowiedź różni się od tego, co już robię. Czy możesz wyjaśnić? –

+1

@Foram czy nawet przeczytałeś pytanie? –

+0

@ B.Money, tak, Cokolwiek zrozumiałem na podstawie twojego pytania, chcesz odtwarzać utwór z UIWebView bez dotykania go, to jest tak szybko, jak aplikacja się ładuje, prawda? –

1

Masz "autoplay" "na" w javascriptu strony internetowej ładujesz w widoku sieciowym.

1
- (void)videoThumb:(NSString *)urlString frame:(CGRect)frame { 
     NSString *embedHTML = @"\ 
     <html><head>\ 
     <style type=\"text/css\">\ 
     body {\ 
     background-color: transparent; 
     color: white; 
     }\ 
     </style>\ 
     </head><body style=\"margin:0\">\ 
     <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \ 
     width=\"%0.0f\" height=\"%0.0f\"></embed>\ 
     </body></html>"; 


    NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width,frame.size.height]; 

    [webView loadHTMLString:html baseURL:nil]; 
    [self.view addSubview:webView]; 
    [webView release]; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    //Include above function to your page and call it by passing the urlstring 
    //frame : this parameter needs the size of the thumb you want to use. 
    [self videoThumb:url:frame]; 
} 

Po prostu zadzwoń do wideoMusi funkcja, przekazując adres URL, w którym chcesz grać i po prostu gotowe.

+0

http://stackoverflow.com/questions/9992735/video-playing-automatically-in-uiwebview/9993698#comment22222207_9993698 odnoszą się do tego samego pytania i odpowiedzi na ten link, odwiedź to będzie pomocne dla Ciebie. – Kuldeep

Powiązane problemy