iphone - MPMoviePlayerController 播放 YouTube 视频
<p><p>如何在 iPhone 上的 MPMoviePlayerController 中播放 YouTube 视频,同时避免进入全屏模式?</p>
<p>这里提出了这个问题:<a href="https://stackoverflow.com/questions/6911171/mpmovieplayercontroller-is-playing-youtube-video" rel="noreferrer noopener nofollow">MPMoviePlayerController is playing YouTube video?</a>在这里:<a href="https://stackoverflow.com/questions/5708236/play-youtube-video-in-mpmovieplayercontroller-or-play-rtsp-3gp-link" rel="noreferrer noopener nofollow">Play Youtube video in MPMoviePlayerController or play RTSP - 3GP link</a>有答案声称这种功能是不可能的。</p>
<p>然而,Deja 这个应用程序具有我想要的功能:一个无缝的 MPMoviePlayerController,我可以显式控制它的框架。 <a href="http://itunes.apple.com/app/deja/id417625158" rel="noreferrer noopener nofollow">http://itunes.apple.com/app/deja/id417625158</a> </p>
<p>这是怎么做到的!?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>将此示例添加到您的项目中
实例化 <em>YoutubeStreamPathExtractorTest</em></p>
<p>调用 <strong>YoutubeStreamPathExtractorTest</strong> 实例的 <strong><em>test</em></strong> 方法。
关注日志并快乐</p>
<pre><code>#import "AFHTTPRequestOperationManager.h"
#import <MediaPlayer/MediaPlayer.h>
typedef void (^CallbackBlock)(NSArray* result, NSError* error);
static NSString* const kYouTubeStreamPathPattern = @"\\\"url_encoded_fmt_stream_map\\\\\":.*?url=(.*?)\\\\u0026";
@interface YoutubeStreamPathExtractorTest : NSObject
- (void)test;
- (void)youtubeURLPath:(NSString*)youtubeURLPath extractStreamURLPathsWithCallback:(CallbackBlock)callback;
@end
@implementation YoutubeStreamPathExtractorTest
- (void) test {
NSString* path = @"http://www.youtube.com/watch?v=TEV5DZpAXSw";
[self youtubeURLPath:path extractStreamURLPathsWithCallback:^(NSArray *result, NSError *error) {
if (error){
NSLog(@"extracting error:%@",);
}
for(NSString* streamURLPath in result) {
NSLog(@"streamURLPath:%@",streamURLPath);
/*
NSURL* url = ;
MPMoviePlayerController* mpMoviePlayerController_ = [ initWithContentURL:url];
mpMoviePlayerController_.controlStyle = MPMovieControlStyleDefault;
;
*/
}
}];
}
- (void)youtubeURLPath:(NSString*)youtubeURLPath extractStreamURLPathsWithCallback:(CallbackBlock)callback {
__block NSMutableArray* resultArray = ;
AFHTTPRequestOperationManager* manager = [ initWithBaseURL:nil];
manager.responseSerializer = ;
manager.responseSerializer.acceptableContentTypes = ;
[manager GET:youtubeURLPath
parameters:nil
success:^(AFHTTPRequestOperation* operation, id responseObject) {
NSData* data = (NSData*)responseObject;
NSString* string = [ initWithData:data encoding:NSUTF8StringEncoding];
NSError* error = nil;
NSRegularExpression* expression = [NSRegularExpression regularExpressionWithPattern:kYouTubeStreamPathPattern
options:NSRegularExpressionCaseInsensitive
error:&error];
NSRange range = NSMakeRange(0,);
NSArray* matches =;
for(NSTextCheckingResult* checkingResult in matches) {
if (>1){
NSString* resultStr = ];
//remove extra slashes
];
}
}
if (callback) {
callback(resultArray,error);
}
} failure:^(AFHTTPRequestOperation* operation, NSError* error) {
if (callback) {
callback(resultArray, error);
}
}];
}
@end
</code></pre></p>
<p style="font-size: 20px;">关于iphone - MPMoviePlayerController 播放 YouTube 视频,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/10411250/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/10411250/
</a>
</p>
页:
[1]