6

で YouTube 動画を取得するにはどうすればよいですか? また、動画再生の- ボタンUITableViewCellを処理するにはどうすればよいですか?DoneUIWebView

ビデオをビューに埋め込みましたが、画像が好きです。そしてDone、この画像にこのボタンが必要です:

スクリーンショット

前のビューではなく、そのビューに戻ったときに別の画面を開きたい。

-(void)viewDidLoad {
    [super viewDidLoad];
    videoURL = [[NSString alloc]init];
    videoURL =@"http://www.youtube.com/watch?v=aE2b75FFZPI";
    [self embedYouTube:videoURL frame:CGRectMake(10, 85, 300, 180)];
}


- (void)embedYouTube:(NSString*)url frame:(CGRect)frame {  
    NSString* embedHTML = @"\ <html><head>\ <style type=\"text/css\">\ body {\ background-color: transparent;\ color: red;\ }\ </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, url, frame.size.width, frame.size.height];  
    if (videoView == nil) {  
        videoView = [[UIWebView alloc] initWithFrame:frame];  
        [self.view addSubview:videoView];  
        NSLog(@"html%@",html);
    }  

    [videoView loadHTMLString:html baseURL:nil];  
}

これについて助けが必要です。検索しましたが、何も得られませんでした。

4

2 に答える 2

0

What your are looking to do involves messing with the mediaplayer used by UIWebView. This can be done by monitoring uiviewanimation notifications and then going through a bunch of subviews but it will involve using private methods and therefore is not recommended especially since the way the private media player behaves changes with each os. I would recommend using jerrylroberts answer and getting direct links to the YouTube videos.

于 2013-07-20T03:11:17.343 に答える
0

これはしばらく答えられなかったので、私は提案をするかもしれないと思った. 最終結果はあなたが探しているものと同じだと思いますが、そこにたどり着くまでの道のりは少し異なります。

私の理解では、クリックすると再生される YouTube 動画のリストを UITableView コントローラーに表示する必要があります。私のアプリケーションの 1 つでこのシナリオを処理した方法を次に示します。

  1. リストに入れたい動画の RSS フィードを取得する必要があります。それはとても簡単です... ユーザー向けの場合、フォーマットはhttp://www.youtube.com/rss/user/{USERNAME}/videos.rssです
  2. そのため、そこから RSS フィードを解析して、タイトル、説明、サムネイル、ビデオへのリンクを含むオブジェクトのリストにする必要があります。これらはすべて RSS で提供されており、私はNSXMLParserを使用して作業を行いました。
  3. 操作する値オブジェクトの適切なリストを取得したら、あとはテーブルでMPMoviePlayerViewControllerを起動し、ムービーを再生する URL を渡すだけです。

didSelectRowAtIndexPath の実装

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    /** self.items is just a mutable array of video objects that is the underlying 
        datasource for the table.  The Video object is just a simple value object 
        I created myself */
    Video *video = [self.items objectAtIndex:[indexPath row]];

    MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:video.video]];

    [self presentMoviePlayerViewControllerAnimated:mp];

    [mp release];
}

私のビデオクラスのインターフェースは次のようになります

@interface Video : NSManagedObject {

@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * link;
@property (nonatomic, retain) NSString * comments;
@property (nonatomic, retain) NSString * thumbnail;
@property (nonatomic, retain) NSString * pubDate;
@property (nonatomic, retain) NSString * video;
@property (nonatomic, retain) NSString * guid;
@property (nonatomic, retain) NSString * desc;

@end

これで、YouTube 動画を UITableViewController に簡単に表示できます。XML の構文解析については説明しません。その方法については、大量のドキュメントが公開されています。私は簡単なグーグルをやっただけで、このブログは実際に私が話していることの要点になります:

http://useyourloaf.com/blog/2010/10/16/parsing-an-rss-feed-using-nsxmlparser.html

これでうまくいくことを願っています。これはマークアップを WebView に配置する方法ではないことはわかっていますが、この方法の方がより直感的で、多くの応答がなかったので、うまくいけば実行できるようになると思います。

于 2012-06-22T17:31:37.823 に答える