Embedding Videos on a Website¶
Dailymotion provides a simple way to embed videos on your website. On each video pages, users can copy/past an embed code. This embed code can also be obtained using the oEmbed protocol or through the Graph API. Note that our new iframe embeds are compatible with most mobile platforms like iOS, Android and Bada and some connected TVs.
If you need to control the playback of the video, you can opt for our Player API.
See API Reference to get the list of objects exposed by the APIs.
Embedding Videos in an iOS Application¶
Our new iframe based embeds are compatible with most mobile platforms (iOS, Android, Bada...). Embeded videos will thus perfectly work in Mobile Safari. Our embed player can also be used inside your iOS application:
If you load a webpage inside an UIWebView containing Dailymotion iframe embeds, they will just work. Although, you have to make sure you’re using the loadRequest: method to load the page. There’s some known issues if you are loading the HTML using the loadHTMLString:baseURL:: the video will play but it won’t go back to your page once the video ends. To workaround this issue, you may choose to write the HTML into a file so you can use loadRequest: with a file:// URL. There’s also some more advanced/performant solutions like NSURLCache poisoning, but this goes beyond the scope of this documentation.
If you need to render a single video outsite a webpage in your app, an alternate solution is to directly load the src of the iframe in a UIWebView which then can be sized and place anywhere you want in your application. Use the embed_url field of the API (see Video) as URL and load it like this:
webview = [[UIWebView alloc] init]; [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:embedURL]]];
To publish videos on Dailymotion using the API, you have to follow several steps as described below. Note that most of those steps are implemented for your by our provided SDKs.
To publish a video, follow the following steps:
Authenticate the user
See authentication guide for more info
Get an upload URL
Perform an HTTP GET to /file/upload to get an upload URL. If you plan to make the end-user to post the video on this URL, you can set a callback URL to get your service to be called once upload finished. Add the callback_url query-string parameter to the URL with the encoded URL as value.
Post the video
Make the end-user to POST (or POST yourself) using multipart/form-data content-type with the file data in the file field:
curl -F 'file=@/path/to/video.mp4' $upload_url
Get the file URL
Once POST finished, the upload server will return a JSON object if you didn’t provide a callback URL or will add query-string parameters to callback URL if you set one. The only field you need is the url field.
Create the video object
With the just created file URL, you can perform an HTTP POST to /me/videos?url=THE_URL. The id of the newly created video will be return in response.
Publish the video
Once video object is created, the video isn’t published. You have to perform an HTTP POST on the /video/VIDEO_ID with the fields you want to modify. Some fields like title, tags and channel are mandatory before you are able to publish the video. Set those field with the method, and set published field to true to publish the video.
Note that you can perform step 4 and 5 in a single request by passing all the fields info in the initial POST.