Code Monkey home page Code Monkey logo

unityyoutubeplayer's Introduction

UnityYoutubePlayer

Play and download youtube videos in Unity using youtube-dl and Unity's VideoPlayer, and uses youtube-dl-server to fetch metadata from youtube-dl.

Preview

How To Install

This package uses the scoped registry feature to import dependent packages. Please add the following sections to the package manifest file (Packages/manifest.json).

To the scopedRegistries section:

{
  "name": "iBicha",
  "url": "https://registry.npmjs.com",
  "scopes": [ "com.ibicha" ]
}

To the dependencies section:

"com.ibicha.youtube-player": "1.3.2"

After changes, the manifest file should look like below:

{
  "scopedRegistries": [
    {
      "name": "iBicha",
      "url": "https://registry.npmjs.com",
      "scopes": [ "com.ibicha" ]
    }
  ],
  "dependencies": {
    "com.ibicha.youtube-player": "1.3.2",
    ...

Usage

  • A minimalistic example:
public class SimpleYoutubeVideo : MonoBehaviour
{
    void Start()
    {
        GetComponent<VideoPlayer>().PlayYoutubeVideoAsync("https://www.youtube.com/watch?v=1PuGuqpHQGo");
    }
}

Or,

  • Add a YoutubePlayer component on a GameObject with a VideoPlayer. Set the url in the inspector. The YoutubePlayer will follow the Play On Awake setting of the video player. You can also call YoutubePlayer.PlayVideoAsync.

  • In addition, you can call YoutubePlayer.DownloadVideoAsync to download the video to a file instead. See the DownloadYoutubeVideo as an example.

  • VideoPlayerProgress allows to display the progress of the video, as well as seeking.

  • See Assets\YoutubePlayer\Scenes for more examples.

Dependencies

UnityYoutubePlayer uses youtube-dl for parsing webpages and getting a raw video url that Unity's VideoPlayer can play. To allow maximum platform compatibilty (e.g. mobile, desktop) and to be able to update the library without rebuilding the game, we're using youtube-dl-server web API.

The package uses a free instance of the server hosted on heroku (shared between everyone). For better reliability and performance, it is recommanded to host this on your own.

How do I host my own youtube-dl server?

  • Go to youtube-dl-server
  • Click the Deploy to Heroku purple button
  • Finish the setup on Heroku.
  • Make YoutubePlayer use your newly hosted instance: To make YoutubePlayer use your instance of the server, make sure to set the ServerUrl before making calls to youtube APIs, e.g.
YoutubeDl.ServerUrl = "http://your-self-hosted-server.com";

For reference, the default instance is

YoutubeDl.ServerUrl = "https://unity-youtube-dl-server.herokuapp.com";

And you can test it in the browser: https://unity-youtube-dl-server.herokuapp.com/v1/video?url=https://www.youtube.com/watch?v=1PuGuqpHQGo

Older version

For the version used with YoutubeExplode, see the legacy/youtube-explode branch. Please note that it has a different license than the current version.

unityyoutubeplayer's People

Contributors

ibicha avatar

Watchers

James Cloos avatar

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.