The
youtube-ios-player-helper
is an open source library that helps you embed a YouTube iframe player into an iOS application. The library creates a WebView
and a bridge between your application’s Objective-C code and the YouTube player’s JavaScript code, thereby allowing the iOS application to control the YouTube player. This article describes the steps to install the library and get started using it from your iOS application.Create a JavaScript bridge so the app can make function calls into the web view; Creating a native event handling architecture so the web view can trigger native events on the parent app; The solution was to create an abstraction made up of: Declarative Markup Language: for describing how to embed a web view into a native app. Creating an app may sound like a difficult process and if you were truly coding an app yourself, I might agree - but with Fluid all you need to know is the URL for the site you want to turn into.
- You will need a Mac computer with Xcode to specify iOS as the target platform. Your app's index.html body content goes into the body of /www/index.html. Perform these three simple steps to update it. Add hosted webpage as an app. If your application is already hosted on a server, converting your web app is very easy independent of the.
- I'm an iOS and Mac developer. I use Xcode all day with Swift and Objective-C. I recently had the need to work on a small website project. This isn't what I normally do. I use TextMate as my single-file text editor, alongside Xcode. But I found the app very annoying for working in a web project with multiple files. There's probably a way that.
Installation
This article assumes you have created a new Single View Application iOS project targeting the latest version of iOS, and that you add the following files when creating the project:
Main.storyboard
ViewController.h
ViewController.m
You can install the library via CocoaPods or by copying the library and source files from the project’s GitHub page.
- The library is available to install via CocoaPods. Alternatively, the library and source files are available via the project’s GitHub page and can be copied into an existing project.
Install the library via CocoaPods
If your project uses CocoaPods, add the line below to your Podfile to install the library. In that line, replace
x.y.z
with the latest pod version, which will be identified on the project’s GitHub page.At the command line prompt, type
pod install
to update your workspace with the dependencies.Tip: Remember that when using CocoaPods, you must open the
.xcworkspace
file in Xcode, not the .xcodeproj
file.Check out the CocoaPods tutorial to learn more.
Manually install the library
To install the helper library manually, either download the source via GitHub’s download link or clone the repository. Once you have a local copy of the code, follow these steps:
- Open the sample project in Xcode or Finder.
- Select
YTPlayerView.h
,YTPlayerView.m
, and the Assets folder. If you open the workspace in Xcode, these are available under Pods -> Development Pods -> YouTube-Player-iOS-Helper and Pods -> Development Pods -> YouTube-Player-iOS-Helper -> Resources. In the Finder, these are available in the project's root directory in the Classes and Assets directories. - Drag these files and folders into your project. Make sure the Copy items into destination group’s folder option is checked. When dragging the Assets folder, make sure that the Create Folder References for any added folders option is checked.
The library should now be installed.
Add a YTPlayerView
via Interface Builder or the Storyboard
To add a
YTPlayerView
via Interface Builder or the Storyboard: - Drag a
UIView
instance onto your View. - Select the Identity Inspector and change the class of the view to
YTPlayerView
. - Open
ViewController.h
and add the following header:Also add the following property: - In Interface Builder, create a connection from the View element that you defined in the previous step to your View Controller's
playerView
property. - Now open
ViewController.m
and add the following code to the end of yourviewDidLoad
method:
Build and run your application. When the video thumbnail loads, tap the video thumbnail to launch the fullscreen video player.
Control video playback
The
ViewController::loadWithVideoId:
method has a variant, loadWithVideoId:playerVars:
, that allows developers to pass additional player variables to the view. These player variables correspond to the player parameters in the IFrame Player API. The playsinline
parameter enables the video to play directly in the view rather than playing fullscreen. When a video is playing inline, the containing iOS application can programmatically control playback.Replace the
loadWithVideoId:
call with this code:Open up the storyboard or Interface Builder. Drag two buttons onto your View, labeling them Play and Stop. Open
ViewController.h
and add these methods, which will be mapped to the buttons:Now open
ViewController.m
and define these two functions:Most of the IFrame Player API functions have Objective-C equivalents, though some of the naming may differ slightly to more closely match Objective-C coding guidelines. Notable exceptions are methods controlling the volume of the video, since these are controlled by the phone hardware or with built in
UIView
instances designed for this purpose, such as MPVolumeView
.Open your storyboard or Interface Builder and control-drag to connect the Play and Stop buttons to the
playVideo:
and stopVideo:
methods.Now build and run the application. Once the video thumbnail loads, you should be able to play and stop the video using native controls in addition to the player controls.
Handle player callbacks
It can be useful to programmatically handle playback events, such as playback state changes and playback errors. In the JavaScript API, this is done with event listeners. In Objective-C,this is done with a delegate.
The following code shows how to update the interface declaration in
ViewController.h
so the class conforms to the delegate protocol. Change ViewController.h
’s interface declaration as follows:YTPlayerViewDelegate
is a protocol for handling playback events in the player. To update ViewController.m
to handle some of the events, you first need to set the ViewController
instance as the delegate of the YTPlayerView
instance. To make this change, add the following line to the viewDidLoad
method in ViewController.h
.Now add the following method to
ViewController.m
:Build and run the application. Watch the log output in Xcode as the player state changes. You should see updates when the video is played or stopped.
The library provides the constants that begin with the
kYT*
prefix for convenience and readability. For a full list of these constants, look at YTPlayerView.m
.Best practices and limitations
The library builds on top of the IFrame Player API by creating a
WebView
and rendering the HTML and JavaScript required for a basic player. The library's goal is to be as easy-to-use as possible, bundling methods that developers frequently have to write into a package. There are a few limitations that should be noted:- The library does not support concurrent video playback in multiple
YTPlayerView
instances. If your application has multipleYTPlayerView
instances, a recommended best practice is to pause or stop playback in any existing instances before starting playback in a different instance. In the example application that ships with the project, the ViewControllers make use ofNSNotificationCenter
to dispatch notifications that playback is about to begin. Other ViewControllers are notified and will pause playback in theirYTPlayerView
instances. - Reuse your existing, loaded
YTPlayerView
instances when possible. When a video needs to be changed in a View, don't create a newUIView
instance or a newYTPlayerView
instance, and don't call eitherloadVideoId:
orloadPlaylistId:
. Instead, use thecueVideoById:startSeconds:
family of functions, which do not reload theWebView
. There is a noticeable delay when loading the entire IFrame player. - This player cannot play private videos, but it can play unlisted videos. Since this library wraps the existing iframe player, the player's behavior should be nearly identical to that of a player embedded on a webpage in a mobile browser.
Contributions
Since this is an open-source project, please submit fixes and improvements to the master branch of the GitHub project.
Today’s blog post is brought to you by Dan Parish a Program Manager on the Excel Web App team.
New! See the end of this post for updates on how to embed.
One of the feature requests we frequently get for Excel Web App is “it would be great if there was a way to embed my workbook in my blog”. Well, starting today, if you have an Excel workbook (xlsx or xlsb only) or a PowerPoint presentation on SkyDrive, you can embed them! In fact, the following embedded PowerPoint presentation will show you how:
There is also a help article (referenced at the end of the presentation) that contains all of the details of how to embed an Excel workbook.
Once you’ve chosen to embed an Excel workbook on SkyDrive, you’ll see the default embed code and a preview of what it will look like on the embed page:
You don’t have to stick with the default embed code though, since the embed code for Excel Web App is also customizable. The embed page contains a link to a help article that shows you how you can customize the embed code to get the embedded workbook to look and behave exactly how you want it to. For example you can have the embedded viewer show only a particular item, you can set the active cell, and you can modify the types of interactivity that are allowed such as sorting and filtering, or typing.
Excel workbooks that are embedded are still “live”, so whenever you update the source workbook, the embedded viewer will display that updated content as well. However, modifications that people make in the embedded viewer are always personal and temporary (only for that browser session), and so don’t affect the underlying workbook itself. This allows people consuming your content to explore it themselves without changing it for everyone.
Let’s look at a few examples of how you can use an embedded Excel Web App in your blog. Let’s say you are on a diet, and want to use the power of peer pressure to keep you on it. So you weigh yourself weekly, plug the result into an Excel workbook, and chart your progress. Now you can put that chart in your blog for your friends and family to see, just like so:
The embed code for this looks as follows:
<iframe src=”http://r.office.microsoft.com/r/rlidExcelEmbed?su=-3211708242785571568&Fi=SDD36DB85E9A926D10!108&AllowInteractivity=False&Item=WeightChart” width=”385” height=”335” frameborder=”0″ scrolling=”no”></iframe>
Note that I’ve changed the URL provided by the embed page as shown in red. I’ve specified a specific item to display using the Item parameter, which in this case is the name of the chart. I’ve also customized the height and width of the IFRAME to make it fit my chart perfectly.
So everyone loves your chart, but you continually get requests for how to calculate BMI as well. You’ve already created a workbook that does just that, so now you can simply embed it in your blog and point people there so they can use it too:
Wordpress Embed Webpage
The embed code for this looks as follows:
<iframe src=”http://r.office.microsoft.com/r/rlidExcelEmbed?su=-3211708242785571568&Fi=SDD36DB85E9A926D10!107&AllowInteractivity=True&AllowTyping=True&Item=BMICalculator&ActiveCell=’BMI Calculator’!G4” width=”440” height=”615” frameborder=”0″ scrolling=”no”></iframe>
Note that in this example I’ve used every option that the embedded viewer has: I’ve enabled interactivity which is required to enable typing, I’ve enabled typing to allow people to fill out their height and weight, I’ve specified a specific item to render which in this case is a named range, and I’ve set the active cell.
If you’d like to see the full workbook an embedded viewer is based on, you can click the icon, which will navigate you to the public workbook on SkyDrive. If you’d like to re-embed an embedded workbook, you can get the code to do that too by clicking the icon.
![Embed Embed](/uploads/1/2/6/3/126383682/721788576.jpg)
We hope you enjoy this new functionality, and please leave any comments and/or questions in the feedback section!
Embed Webpage Into Mac App Xcode 10
New! How-tos, examples, and ideas