How to only get the audio of YouTube videos running? - ios

I've come across a rather strange problem. What I'm trying to do right now is only obtain the audio of a YouTube video for a given link. I've tried a couple of things but it either didn't work or wasn't efficient.
Thus I've decided to ask more experienced iOS developers in here. Thanks in advance.
#implementation ViewController
#synthesize web;
- (void)embedYouTube:(NSString*)url frame:(CGRect)frame{
NSString* embedHTML = #"<html><head> <style type=\"text/css\">body {background-color: transparent;color: white;}</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];
UIWebView *webView =[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[webView loadHTMLString:html baseURL:nil];
[self.view addSubview:webView];
}
-(IBAction)play{
[self embedYouTube:#"http://www.youtube.com/watch?v=iw1aT5c1Lus" frame:CGRectMake(0, 0, 320, 480)];
}

just play the video with your media player, but dont give it a frame, this will play the audio, but not load the image

Related

Unable to move UIWebView to a specified section in iOS11 (iPad)

We have used the below lines of code to move to the web view:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.location.hash=\'#-1\';"]];
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.location.hash=\'#%#\';", index]];
but somehow this code doesn't work only in iPad. Here is how I initialised the web view:
webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[webView setDelegate:self];
[webView.scrollView setDelegate:self];
[webView setBackgroundColor:WHITECOLOR];
[webView setScalesPageToFit:YES];
[webView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview: webView];
Could someone please guide me how to debug it.
In iOS11 location.hash seems to be broken, but it's a simple solution to this.
Instead using an usual combination:
location.hash = "";
location.hash = _some_hash_string_
use javascript below:
var hashElement=document.getElementsByName(_some_hash_string_)[0];
if(hashElement) {
hashElement.scrollIntoView();
} else {
// if the element is not found - scroll to top
document.documentElement.scrollIntoView();
}

Embedding YTPlayerView In UIScrollView

I'm creating a UIScrollView that can hold images and videos from different sources. I first created and added a UIView for each image/video to the UIScrollView, then add the image/video view/layer. This works fine for images and videos using AVFoundation; however, does not work for videos using the Youtube API.
Here's my code for adding the YTPlayerView to the UIView within the UIScrollView:
YTPlayerView * youtubePlayerView = [[YTPlayerView alloc] initWithFrame: CGRectMake(0, 0, self.scrollViewWidth, self.scrollViewHeight)];
youtubePlayerView.bounds = CGRectMake(0, 0, self.scrollViewWidth, self.scrollViewHeight);
NSString * youtubePath = [media getMediaPath]; //Valid Youtube URL as NSString
NSMutableString *videoUrlCopy = [NSMutableString stringWithString:youtubePath];
NSString *vID = [videoUrlCopy lastPathComponent];
NSDictionary *playerVars = #{
#"playsinline" : #1
};
youtubePlayerView.delegate = self;
[contentView addSubview:youtubePlayerView]; //ContentView is subview of UIScrollview
[youtubePlayerView loadWithVideoId:vID playerVars:playerVars];
[youtubePlayerView playVideo];
When I try to load the youtube video with loadWithVideoId, the process terminates within YTPlayerView here: UIWebView *webView = [[UIWebView alloc] initWithFrame:self.bounds]; throwing EXC_BAD_ACCESS.
- (UIWebView *)createNewWebView {
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.bounds];
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
webView.scrollView.scrollEnabled = NO;
webView.scrollView.bounces = NO;
return webView;
}
Interestingly, I've gotten the Youtube videos to show adding the YTPlayerView directly as a subview to self.view. Any suggestions?
I figure it out, using
pod 'youtube-ios-player-helper', :git=>'https://github.com/youtube/youtube-ios-player-helper', :commit=>'head'
instead of using pod 'youtube-ios-player-helper'
Cheers

Adobe Edge animation on IOS7 not working

I'm trying to implement an Adobe Edge animation inside a UIWebView in my IOS7 app. But all I get is a white screen. The same white screen shows up on my iPhone's Safari. The animation runs fine on my laptop's browsers, both Safari and Chrome.
I'm thinking this is an Adobe Edge problem, but here's my IOS code anyway:
NSString *filePathString = [[NSBundle mainBundle] pathForResource:#"YallaBye_Button2" ofType:#"html"];
NSMutableString *html = [[NSMutableString alloc] initWithContentsOfFile:filePathString encoding:NSUTF8StringEncoding error:nil];
NSURL *aURL = [NSURL fileURLWithPath:filePathString];
UIWebView *view = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
view.delegate = self;
[view stringByEvaluatingJavaScriptFromString:#"window.requestAnimationFrame = window.setTimeout;"];
[view loadHTMLString:html baseURL:aURL];
[self.indicatorForPlans addSubview:view];
The indicator works fine without the Adobe Edge html.
I also tried running the [view stringByEvaluatingJavaScriptFromString:#"window.requestAnimationFrame = window.setTimeout;"]; call inside the UIWebViewDelegate method - (void)webViewDidFinishLoad:(UIWebView *)webView but no luck.
Also, researching the forums, I tried changing my transform:translateX(0px); to -webkit-perspective: 1000; -webkit-backface-visibility: hidden; but still just a white screen.
What am I missing?

Unable to load full Facebook comment plugins inside an iOS UIWebView

I have a simple ViewController to load FB comments plugins inside a UIWebView
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 1505.0f)];
NSString * html = #"\
<!DOCTYPE html>\
<html xmlns:fb='http://ogp.me/ns/fb#'>\
<head>\
<meta name='viewport' content='width=device-width, initial-scale=1.0'>\
</head>\
<body style='background-color:red;'>\
\
<div id='fb-root'></div>\
<script>(function(d, s, id) {\
var js, fjs = d.getElementsByTagName(s)[0];\
if (d.getElementById(id)) return;\
js = d.createElement(s); js.id = id;\
js.src = 'http://connect.facebook.net/en_US/all.js#xfbml=1&appId=xxx';\
fjs.parentNode.insertBefore(js, fjs);\
}(document, 'script', 'facebook-jssdk'));</script>\
\
<fb:comments href='http://example.com' num_posts='10'></fb:comments>\
\
</body>\
</html>\
";
[webView loadHTMLString:html baseURL:nil];
[self.view addSubview:webView];
I can see the comments being loaded, but just the height is strange, seems auto resize failed? I can view the whole comments if I am using mobile safari.
you can use this code for displaying the fb comment in iOS UIWebview
UIWebView *fbWebview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 1505)];
[fbWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"https://www.facebook.com/Levis"]]];
CGRect scrollViewFrame = CGRectMake(0, 0, 320, 1024);
UIScrollView *scrollViewMain = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
CGSize scrollViewContentSize = CGSizeMake(320, 1505);
[scrollViewMain setContentSize:scrollViewContentSize];
[scrollViewMain setBounces:NO];
[scrollViewMain setScrollEnabled:YES];
[scrollViewMain setShowsVerticalScrollIndicator:YES];
[scrollViewMain setBackgroundColor:[UIColor redColor]];
[scrollViewMain addSubview:fbWebview];
[self.view addSubview:scrollViewMain];
instead of "https://www.facebook.com/Levis" use your FB URL
this may help you
You need to specify a baseURL
[webView loadHTMLString:html baseURL:[NSURL URLWithString:#"http://www.example.com"]];
#Howard you can use http://www.facebook.com/plugins/comments.php?href=http://www.google.com' scrolling='yes' profile='yes' frameborder='0' style='border:none; overflow:hidden; width:300px; height:30px;' data-href='http://www.google.com' allowTransparency='true'>"
Same problem here. The solution was not to use a local HTML file (or HTML string). Upload the HTML file to an server and use:
NSURL *url = [NSURL URLWithString:#"http://www.blablblab.com/yourfile.html"];
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];
instead of:
[self.webview loadHTMLString:localString baseURL:nil];
I didn't discovered yet why there is a difference in the layout when the file is on a server, but when it is a local file, the height of my Facebook Comments View was always reduced to "height:160". Apparently it's because of the "all.js" facebook script (accordingly to this question).

iOS youtube iframe embed - won't go fullscreen

The video displays on the iPad. You can tap to bring up the controls. The fullscreen button is shown in the lower right, but tapping on it does nothing. It should send the player into fullscreen mode. Is there anything I can add to this code to make it work?
NSString *htmlStr = [NSString stringWithFormat:#"<body style=\"margin:0;padding:0;\" ><iframe class=\"youtube-player\" type=\"text/html\" width=\"420\" height=\"226\" src=\"http://www.youtube.com/embed/%#\" frameborder=\"0\" allowfullscreen></iframe>",video_ID];
UIWebView *videoView = [[UIWebView alloc] initWithFrame:thumb.frame];
videoView.backgroundColor = [UIColor darkGrayColor];
videoView.scrollView.scrollEnabled = NO;
[videoView loadHTMLString:htmlStr baseURL:nil];
[videoCcontainer addSubview:videoView];
Try using embed, and not an iframe: http://mobiledevelopertips.com/video/display-youtube-videos-without-exiting-your-application.html
NSString *youTubeVideoHTML = #"<html><head>\
<body style=\"margin:0\">\
<embed id=\"yt\" src=\"%#\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";

Resources