Does anyone know how to play a facebook video in a UIWebView?
My app uploads video to facebook and retrieves the video's url. I'd like to embed this url into a UIWebView to play back. I've worked this out for youtube but not Facebook. looking for help.
Orpheus!
I’m a few years late lol, but I’ll post the answer here anyway -- in Swift since it’s 2018 ;) -- just in case someone needs it.
You can use the following HTML string:
let embedCode = "<iframe src=\"https://www.facebook.com/plugins/video.php?href=\([INSERT VIDEO URL])&show_text=0&width=\(Int([INSERT WIDTH]))\" width=\"\(Int([INSERT WIDTH]))\" height=\"\(Int([INSERT WIDTH] * 56.25))\" style=\"border:none;overflow:hidden\" scrolling=\”no\" frameborder=\"0\" allowTransparency=\”true\" allowFullScreen=\"true\"></iframe>"
where you replace [INSERT VIDEO URL] with the video URL and [INSERT WIDTH] with the desired web view width.
Then load the HTML into the UIWebView like so:
webView.loadHTMLString(embedCode, baseURL: nil)
Related
I am working on an app in which i have to display videos comes from JSON server some of them are youtube video and some are from other resources.
My problem is when i want to play video the videos which are from youtube link are playing perfectly but the other videos are not playing.
i imported <AVFoundation/AVFoundation.h>, <AVKit/AVKit.h>, MediaPlayer/MediaPlayer.h files also i imported YTPlayerView Files
I am using following code in UIWebView
[self.webvw setAllowsInlineMediaPlayback:YES];
[self.webvw setMediaPlaybackRequiresUserAction:NO];
NSString* embedHTML = [NSString stringWithFormat:#"%#",videoStr];
[self.webvw loadHTMLString:embedHTML baseURL:[[NSBundle mainBundle] resourceURL]];
The other video format is look like as:
"embed_code": "<object width="430" height="344"><embed width="430" height="344" type="application/x-shockwave-flash" wmode="transparent" src="http://xxxxxxx.xxxxxx/static/jscript/player/flowplayer/flowplayer.swf?config={'clip':{'baseUrl': 'http://myconnect.media/file/video/','url': '2017/02/3d045f0f240bfb73305f77c3da4d9218.flv','autoBuffering': true,'autoPlay': false}}"></embed></object>"
I am using YTPlayerView for playing embedded videos in my app. Everything works perfect with ID but video doesn't play with URL. Here is my code
-(IBAction)playVideo:(id)sender{
self.playerView.delegate = self;
self.playerView.hidden = false;
[self.playerView loadVideoByURL:#"https://www.youtube.com/watch?v=KWTULSf29Ho" startSeconds:0 suggestedQuality:kYTPlaybackQualitySmall];
}
The URL has to be in the format youtube.com/v/VIDEO_ID?version=3, your url was wrong.
if you want to achieve the specific format, change your method which for responding user input url, appending ?version=3 with user input url.
check this,i think you forgot load the video into the player
I have many url's like this:
https://www.youtube.com/watch?v=81_2Xb0XB_E&feature=youtube_gdata
I want to see in my app only the video, rather than a youtube page.
How can I go about this?
So far I have tried:
urlValue = [urlValue stringByReplacingOccurrencesOfString:#"watch?v="
withString:#"v/"];
urlValue = [urlValue stringByReplacingOccurrencesOfString:#"&feature"
withString:#"?version=3&f=playlists&app"];
This is the final url :
https://www.youtube.com/v/81_2Xb0XB_E?version=3&f=playlists&app=youtube_gdata_player
And this is how I load it:
NSString *videoHTML = [NSString stringWithFormat:#"<iframe type=\"text/html\" width=\"305\" height=\"180\" src=\"%#\" frameborder=\"0\"></iframe>", urlValue];
For some of them it's ok, I can watch it, but for others, like this url I cant watch. ("Watch this video on youtube . Playback on other website has been disabled by the video owner").
Any idea how can I improve my code? or if it's because of url?
Here is an example of url which is working:
http: //www.youtube.com/v/9M3wwddDec4?version=3&f=playlists&app=youtube_gdata_player
Give this a try HCYoutubeParser
I have used PrimeFaces for playing a youtube video from url.But there is a problem in this tag.Some of the youtube links are playing but some of them are not playing.For example;
this video is playing but this video is not playing.Here is the code;
< p : media value = "http://www.youtube.com/watch?v=mqOo7cYCBAo" width="600"
height="400"
player="flash"/>
you need to check the link. The video link which it plays has some modifications. Its not exactly the same as the one you're trying to play.
https://www.youtube.com/v/KZnUr8lcqjo
https://www.youtube.com/watch?v=mqOo7cYCBAo
Observe the strings after .com
You need to replace the string in proper format to make it play.
I'm creating dynamic WordPress "pin it" buttons and have it working on pictures.
For example, when I generate this URL it launches pinterest's pin it page:
http://pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.mywebsite.com%2Ftest-post%2F&media=http://www.mywebsite.com/wp-content/uploads/2012/09/picture.jpg&description=Test+Post
How do I go about doing this for a Vimeo or Youtube video?
http://pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.mywebsite.com%2Ftest-post%2F&media=________????_________&description=Test+Post
Do I just put a vimeo or youtube URL there?
To pin a Youtube video you just need to media link to be a youtube thumbnail. Pinterest then automatically recognizes it as a video.
To get the youtube thumbnail you need to get the video id from the youtube url as explained more here
var youtubelink = "http://www.youtube.com/embed/wkBstmXvGtk"
var youtubecode = youtubelink.match(/\/embed\/(.*)/)[1];
var pinimage = 'http://img.youtube.com/vi/' + youtubecode + '/0.jpg';
I wrote a full tutorial on it here:
http://thingsilearned.com/things/pin-button
Unfortunately, I think the script used to generate a web-based pin is not capable of handling video.
I utilized the following code...
<img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" />
<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>
...where the URL was the link to the YouTube video (or permalink). The problem is, the pinit.js script does not parse image information from the url or provide a video screenshot for the pin. It comes up blank, and without a value for media, the script won't create the pin.
To confirm the problem is within pinit.js, I substituted that script for pinmarklet.js. What that script does is create an overlay on the page, with the screen shot of a video and a "PIN IT" button overlay on the screen shot. But that's probably not the type of user experience you're looking to present.
One possible option (and you could get away with this through feeding the URL, media and description values dynamically) is to feed the URL with the video URL, create a screenshot and feed that into media, and finally, add the description. The drawback to this is, you'll only be pinning the image and not the video directly.
Sorry to be the bearer of bad news.