开发者

How to load a YouTube video (within app) by clicking on a UIButton?

I am implementing a UITableView containing a list of YouTube videos. Can anyone advise me how I can trigger a YouTube video load within an app after the user clicks on a UIButton (exist in each cell)?

I searched the net but only found implementations involving UIWebViews. Note that I specifically do not want to add a UIWebView to my table view but instead what the trigger point to be from a button or image in the cel开发者_如何转开发l.


You should be able to use MPMoviePlayerController to play the videos.

You can easily set this up to either play fullscreen, or to play in a view embedded in your app's UI. See Apple's Multimedia Programming Guide for more details.


Roughly: Tie the button in your cell class to an action on your controller class, and pass the button itself when clicking via the buttonClicked:(id)sender form. Use the button's superview and then either a viewWithTag: call, or casting and an @property on the cell, to get a reference to a variable or UI element within the cell the button came from which will tell you the URL to load (could just be an index stored in a hidden UILabel for example, which you then look up in the data store backing your UITableView). Then call MPMoviePlayerViewController with that URL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜