Embedding YouTube videos on
Just tested your code, it works fine on an iPhone, Youtube videos are not supported on the iOS simulator though, so you'll need a real device for testing.
How can I position this box?
You are already passing the X (20), Y(20), width(100) and height(100) of the box at this line:
[self embedYouTube:@"http://..." frame:CGRectMake(20, 20, 100, 100)];
To change the position of the view afterwards, you modify its center property:
videoView.center = CGPointMake(200, 100 );
Embed video from youtube.com into iphone app
As far as I'm aware, inline media playback is only supported on iPad, not iPhone. This would be due to size limitations with the screens.
Edit:
I setup a test project, with a UIWebView
and the code:
[webView setAllowsInlineMediaPlayback:YES];
[webView loadHTMLString:@"<embed id=\"yt\" src=\"http://www.youtube.com/watch?v=L9szn1QQfas&fs=0\" type=\"application/x-shockwave-flash\" width=\"300\" height=\"300\"></embed>"
baseURL:nil];
I ran the same exact code on both an iPhone and an iPad, both running iOS 4.2.1.
The results were that the iPhone would only play the video in fullscreen mode, regardless of setting the inline media playback to YES
and the iPad played the video inline. Here's a picture:
embedding youtube video in iphone app
No need to use the embed code. The standard UIWebView aimed at the youtube web address should work fine...
// URL from safari address bar.
NSURL *url = [NSURL URLWithString:@"http://www.youtube.com/watch?v=fDXWW5vX-64"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
Embed youtube video in iOS App
Try this one this is working perfect.
You use youtube Url as "http://www.youtube.com/v/YOU_TUBE_VIDEO_ID".
UIWebView * youTubeWebView=[[UIWebView alloc]initWithFrame:CGRectMake(0,0,320,320)];
youTubeWebView.allowsInlineMediaPlayback=YES;
youTubeWebView.mediaPlaybackRequiresUserAction=NO;
youTubeWebView.mediaPlaybackAllowsAirPlay=YES;
youTubeWebView.delegate=self;
youTubeWebView.scrollView.bounces=NO;
NSString *linkObj=@"http://www.youtube.com/v/1iBIcJFRLBA";//@"http://www.youtube.com/v/6MaSTM769Gk";
NSLog(@"linkObj1_________________%@",linkObj);
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;color: white;}\\</style>\\</head><body style=\"margin:0\">\\<embed webkit-playsinline id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \\width=\"320\" height=\"320\"></embed>\\</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, linkObj];
[youTubeWebView loadHTMLString:html baseURL:nil];
[self.view addSubview:youTubeWebView];
How to embed a Youtube video into my app?
Xcode 8.2 • Swift 3.0.2
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var wv: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
loadYoutube(videoID: "oCm_lnoVf08")
}
func loadYoutube(videoID:String) {
guard
let youtubeURL = URL(string: "https://www.youtube.com/embed/\(videoID)")
else { return }
wv.loadRequest( URLRequest(url: youtubeURL) )
}
}
Xcode 7.3.1 • Swift 2.x
import UIKit
class ViewController: UIViewController {
// create an outlet for your webview
@IBOutlet weak var wv: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// load your you tube video ID
loadYoutube(videoID: "oCm_lnoVf08")
}
func loadYoutube(videoID videoID:String) {
// create a custom youtubeURL with the video ID
guard
let youtubeURL = NSURL(string: "https://www.youtube.com/embed/\(videoID)")
else { return }
// load your web request
wv.loadRequest( NSURLRequest(URL: youtubeURL) )
}
}
iOS Youtube Embedded video playlists
Not shure if its exactly the same issue
but since last week no playlist will work on iOS (iPhone,iPad)
(embedded on a normal webpage)
occurs with both iOS6 and iOS7.
see my post:
Playlist (embedded ) broken on iOS
They still work in all desktop-browsers.
Single videos will work...maybe that is why your 1st example
still works cause its not a real playlist (?)...since it has only one video in it.
Its a bug @ youtube ... their only reply till now (@google api groups) was
"its filed" which ofcourse is nothing ...they could just as well have said
"its not filed" since "filed" means nothing ..they should for a start confirm
that this is a bug ...next they should mention if and when its going to be solved.
Not shure but you may want to add/change a tag ( youtube-api ) not just "youtube" to your first post (if you still can).
youtube-api
youtube-api
Embedding YouTube Video in Trigger.io for iOS
Since YouTube redirects you to its https:// protocol site, you need to whitelist https://youtube.com
-- just whitelisting http://youtube.com
is not enough.
Related Topics
CSS How to Make <Td> a Fixed Height
HTML: How to Retain Formatting in Textarea
Yet Another HTML/CSS Layout Challenge - Full Height Sidebar with Sticky Footer
Difference Between HTML and Dom
Preserve Dynamically Changed HTML on Back Button
How to Style Input File Textbox
Can an HTML Email Body Reference a File Sent as an Attachment (In The Same Email)
How to Make <Input Type="File"/> Accept Only These Types
How to Reuse HTML Like a Template on Multiple Pages
Height of Textarea Does Not Match The Rows in Firefox
Chrome Not Respecting Rem Font Size on Body Tag
Placing an Image to The Top Right Corner - CSS
Wrapping Long Email Addresses in Small Boxes
CSS3 Animation Not Working in Chrome
How to Show a Image Preview in The Browser Without Uploading The Image File to The Server