Giter Club home page Giter Club logo

davidefavia / cordova-plugin-in-app-youtube Goto Github PK

View Code? Open in Web Editor NEW
14.0 4.0 10.0 8 KB

Open YouTube video in app or use the browser as fallback for Android & iOS. Plugin goal is to show YouTube video via native app or mobile website to count for views.

Home Page: https://github.com/davidefavia/cordova-plugin-in-app-youtube

License: MIT License

Java 48.68% Objective-C 44.20% JavaScript 7.12%
cordova cordova-plugin cordova-android-plugin cordova-ios youtube

cordova-plugin-in-app-youtube's Introduction

cordova-plugin-in-app-youtube

Open YouTube video in app or use the browser as fallback for Android & iOS. Plugin goal is to show YouTube video via native app or mobile website to count for views.

If you need to stream YouTube video content without using its own player, just check Glitchbone/CordovaYoutubeVideoPlayer project.

Getting Started

This plugin has been tested with Cordova 6.5.0, Android 7.1.1 and iOS 10.3.

Install via Cordova:

$ cordova plugin add https://github.com/davidefavia/cordova-plugin-in-app-youtube

Reference

window.InAppYouTube.openVideo(videoId, [options, successCallback, errorCallback])

It opens a YouTube video.

Parameters

Parameter Type Default Description
videoId string YouTube video identifier, e.g. 9bZkp7q19f0.
options object {} Use fullscreen = true to enable fullscreen.
successCallback function function() {} Plugin returns result object with videoId (string), options (object) and type (string) key. type can be application or webview depending on which application opened the video.
errorCallback function function() {} Plugin returns error or exception message (string).

Platforms have different behaviors.

Platform YouTube app installed fullscreen option Behavior
Android Yes true YouTube app plays video in landscape mode (even if your app forbids this orientation) in fullscreen inside your app. Back button lets Cordova WebView take focus back.
Android Yes false YouTube app plays video in portrait mode inside your app. Some related content is shown below the video player. Back button lets the Cordova WebView take focus back.
Android No true URL https://www.youtube.com/embed/<video-id> is opened in the default browser in full window size, browser toolbar is visible. Video is stopped by default due to Chrome for Android policies.
Android No false URL https://www.youtube.com/watch?v=<video-id> is opened in the default browser, browser toolbar is visible. Video is stopped by default due to Chrome for Android policies.
iOS Yes true YouTube app plays video in portrait mode outside your app. Some related content is shown below the video player. Back button in top corner lets the Cordova WebView take focus back.
iOS Yes false YouTube app plays video in portrait mode outside your app. Some related content is shown below the video player. Back button in top corner lets the Cordova WebView take focus back.
iOS No true URL https://www.youtube.com/embed/<video-id> is opened in the Safari in full window size, toolbar is visible. Video is stopped by default due to Apple policies.
iOS No false URL https://www.youtube.com/watch?v=<video-id> is opened in the default browser, browser toolbar is visible. Video is stopped by default due to Apple policies.

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Device Ready Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    function onLoad() {
      document.addEventListener("deviceready", onDeviceReady, false);
    }

    // device APIs are available
    function onDeviceReady() {
      // Now safe to use device APIs
      try {
        window.InAppYouTube.openVideo('9bZkp7q19f0', {
          fullscreen: true
        }, function(result) {
          // console.log(JSON.stringify(result));
        }, function(reason) {
          // console.log(reason);
        });
      } catch(e) {
        // Exception!
      }
    }

    </script>
  </head>
  <body onload="onLoad()">
  </body>
</html>

License

This project is licensed under the MIT License - see the LICENSE file for details.

cordova-plugin-in-app-youtube's People

Contributors

davidefavia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cordova-plugin-in-app-youtube's Issues

playlists?

Hey,

is it possible to open a playlist instead of a single video?

regards,

Kevin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.