Play YouTube videos with MPMoviePlayerController instead of UIWebView
The only way to have a youtube video play inside your own app is to create a UIWebView
with the embed tag from Youtube for the movie you want to play as the UIWebView's
content. UIWebView
will detect that the embedded object is a Youtube link, and the web view's content will be the youtube preview for the video. When your user clicks the preview, the video will be shown in an MPMoviePlayerController. This is the technique described at the link that Muxecoid provided (how to play youtube videos within an application), and this is (as far as I know of) the only way to have a youtube video play within an application. You can still have the Youtube application launch by passing the youtube URL to -[UIApplication openURL:]
, but of course this closes your own application which is often undesirable.
Unfortunately, there's no way to directly play a youtube video with MPMoviePlayerController
because youtube does not expose direct links to the video files.
Play YouTube videos with MPMoviePlayerController instead of UIWebView
The only way to have a youtube video play inside your own app is to create a UIWebView
with the embed tag from Youtube for the movie you want to play as the UIWebView's
content. UIWebView
will detect that the embedded object is a Youtube link, and the web view's content will be the youtube preview for the video. When your user clicks the preview, the video will be shown in an MPMoviePlayerController. This is the technique described at the link that Muxecoid provided (how to play youtube videos within an application), and this is (as far as I know of) the only way to have a youtube video play within an application. You can still have the Youtube application launch by passing the youtube URL to -[UIApplication openURL:]
, but of course this closes your own application which is often undesirable.
Unfortunately, there's no way to directly play a youtube video with MPMoviePlayerController
because youtube does not expose direct links to the video files.
How to play youtube video using MPMoviePlayerController?
You cannot play a YouTube vidoe URL in MPMoviePlayerController. For this you have to use
youtube-iso-player-helper - But you cannot play private video URL in youtube-iso-player-helper
XCDYoutubeKit - It is against YouTube Terms and Service.
How to play YouTube videos using MPMoviePlayer?
I think the only official way is to make it play inside a UIWebView.
However there is a project called XCDYouTubeKit that, I think, will do exactly what you want:
https://github.com/0xced/XCDYouTubeKit
That's allows you to make a youtube view play in a specific frame, that's maybe what your looking for.
example of use:
NSString *videoIdentifier = @"EdeVaT-zZt4"; // A 11 characters YouTube video identifier
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:videoIdentifier completionHandler:^(XCDYouTubeVideo *video, NSError *error) {
if (video)
{
// Do something with the `video` object
}
else
{
// Handle error
}
}];
Documentation is available here: http://cocoadocs.org/docsets/XCDYouTubeKit/2.0.1/
Good luck
How to play youtube video?
Like this?
NSString *exampleUrlString = @"https://www.youtube.com/embed/2bfP3TZHUzY?wmode=opaque&rel=0&autohide=1&showinfo=0&wmode=transparent";
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:exampleUrlString]]];
[self.view addSubview:webView];
Play YouTube videos in iPhone app without using UIWebView?
Mr.Yuvaraj.M your above code is correct. Please run the project in your iPhone/iPod touch device. The youtube videos may not support/not work in Simulator. Please check on this. Thanks.
Playing youtube video with MPMoviePlayerController
Make use of custom LBYouTubePlayerViewController
It is a subclass of MPMoviePlayerViewController
.
LBYouTubeView is just a small view that is able to display YouTube videos in a MPMoviePlayerController
. You even have the choice between high-quality and standard quality stream.
It just loads the HTML code of YouTube's mobile website and looks for the data in the script tag.
LBYouTubeView doesn't use UIWebView which makes it faster and look cleaner.
How to Open Youtube video in MPMoviePlayerController and Play it
if possible to open your URL
into UIWebview
then take a button in your class and redirect it on to the WebsiteViewController
class may be it helps u
WebsiteViewController.h ///----
@interface WebsiteViewController : UIViewController <UIWebViewDelegate>
{
IBOutlet UIWebView *webView;
}
@property(nonatomic,retain) IBOutlet UIWebView *webView;
WebsiteViewController.m ///---
-(void)viewDidLoad {
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:@"url"];
[self.webView setScalesPageToFit:YES];
[self.webView loadRequest:request];
[request release];
}
Related Topics
Periodic iOS Background Location Updates
Creating a Left-Arrow Button (Like Uinavigationbar'S "Back" Style) on a Uitoolbar
Delete/Reset All Entries in Core Data
Cell Spacing in Uicollectionview
Custom Uitableviewcell from Nib in Swift
How to Find Specific Subclass of Nsmanagedobject
Swift: How to Split Up a [String] Resulting in a [[String]] With a Given Subarray Size
Libc++Abi.Dylib: Terminating With Uncaught Exception of Type Nsexception (Lldb)
Error: 'Flutter/Flutter.H' File Not Found When Flutter Run on Ios
How to Create Dispatch Queue in Swift 3
Eliminate Extra Separators Below Uitableview
Move Textfield When Keyboard Appears Swift
Hide Strange Unwanted Xcode Logs
How to Programmatically Get the MAC Address of an Iphone
How to Make a Uitextfield Move Up When the Keyboard Is Present - on Starting to Edit