{"id":15390258,"url":"https://github.com/gajus/youtube-player","last_synced_at":"2025-05-15T16:01:48.637Z","repository":{"id":27528884,"uuid":"31009998","full_name":"gajus/youtube-player","owner":"gajus","description":"YouTube iframe API abstraction.","archived":false,"fork":false,"pushed_at":"2023-07-19T07:48:19.000Z","size":2054,"stargazers_count":379,"open_issues_count":24,"forks_count":79,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-05-10T05:20:31.260Z","etag":null,"topics":["api-sdk","video-player","youtube"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gajus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"gajus","patreon":"gajus"}},"created_at":"2015-02-19T10:13:13.000Z","updated_at":"2025-04-30T04:41:41.000Z","dependencies_parsed_at":"2023-01-14T07:45:33.517Z","dependency_job_id":"0b195357-64ac-48e1-bb17-5037ddc8a370","html_url":"https://github.com/gajus/youtube-player","commit_stats":{"total_commits":101,"total_committers":17,"mean_commits":"5.9411764705882355","dds":0.6534653465346535,"last_synced_commit":"9fcfab890602df6ba72c413653c59de3debf0bb0"},"previous_names":["gajus/playtube"],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fyoutube-player","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fyoutube-player/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fyoutube-player/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fyoutube-player/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gajus","download_url":"https://codeload.github.com/gajus/youtube-player/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254374388,"owners_count":22060609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-sdk","video-player","youtube"],"created_at":"2024-10-01T15:05:07.840Z","updated_at":"2025-05-15T16:01:48.576Z","avatar_url":"https://github.com/gajus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/gajus","https://patreon.com/gajus"],"categories":["Video"],"sub_categories":["Docker Custom Builds"],"readme":"# YouTube Player\n\n[![Travis build status](http://img.shields.io/travis/gajus/youtube-player/master.svg?style=flat-square)](https://travis-ci.org/gajus/youtube-player)\n[![NPM version](http://img.shields.io/npm/v/youtube-player.svg?style=flat-square)](https://www.npmjs.org/package/youtube-player)\n[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)\n[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social\u0026label=Follow)](https://twitter.com/kuizinas)\n\n* [Usage](#usage)\n  * [Events](#events)\n* [Polyfills](#polyfills)\n* [Examples](#examples)\n* [Debugging](#debugging)\n* [Download](#download)\n* [Running the Examples](#running-the-examples)\n\n`youtube-player` is an abstraction of [YouTube IFrame Player API](https://developers.google.com/youtube/iframe_api_reference) (YIPA).\n\nThe downsides of using YouTube IFrame Player API are:\n\n* Requires to define callbacks in the global scope (`window`).\n* Requires to track the state of a player (e.g. you must ensure that video player is \"ready\" before you can use the API).\n\n`youtube-player`:\n\n* Registers listeners required to establish when YIPA has been loaded.\n* Does not overwrite global YIPA callback functions.\n* Queues player API calls until when video player is \"ready\".\n\n##\n\n## Usage\n\n```js\n/**\n * @typedef options\n * @see https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player\n * @param {Number} width\n * @param {Number} height\n * @param {String} videoId\n * @param {Object} playerVars\n * @param {Object} events\n */\n\n/**\n * @typedef YT.Player\n * @see https://developers.google.com/youtube/iframe_api_reference\n * */\n\n/**\n * A factory function used to produce an instance of YT.Player and queue function calls and proxy events of the resulting object.\n *\n * @param {YT.Player|HTMLElement|String} elementId Either An existing YT.Player instance,\n * the DOM element or the id of the HTML element where the API will insert an \u003ciframe\u003e.\n * @param {YouTubePlayer~options} options See `options` (Ignored when using an existing YT.Player instance).\n * @param {boolean} strictState A flag designating whether or not to wait for\n * an acceptable state when calling supported functions. Default: `false`.\n * See `FunctionStateMap.js` for supported functions and acceptable states.\n * @returns {Object}\n */\nimport YouTubePlayer from 'youtube-player';\n```\n\n`youtube-player` is a factory function.\n\n The resulting object exposes all [functions of an instance of `YT.Player`](https://developers.google.com/youtube/iframe_api_reference#Functions). The difference is that the function body is wrapped in a promise. This promise is resolved only when the player has finished loading and is ready to begin receiving API calls (`onReady`). Therefore, all function calls are queued and replayed only when player is ready.\n\n This encapsulation does not affect the API other than making every function return a promise.\n\n```js\nlet player;\n\nplayer = YouTubePlayer('video-player');\n\n// 'loadVideoById' is queued until the player is ready to receive API calls.\nplayer.loadVideoById('M7lc1UVf-VE');\n\n// 'playVideo' is queue until the player is ready to received API calls and after 'loadVideoById' has been called.\nplayer.playVideo();\n\n// 'stopVideo' is queued after 'playVideo'.\nplayer\n    .stopVideo()\n    .then(() =\u003e {\n        // Every function returns a promise that is resolved after the target function has been executed.\n    });\n```\n\n### Events\n\n`player.on` event emitter is used to listen to all [YouTube IFrame Player API events](https://developers.google.com/youtube/iframe_api_reference#Events), e.g.\n\n```js\nplayer.on('stateChange', (event) =\u003e {\n    // event.data\n});\n\n```\n\n`player.off` removes a previously added event listener, e.g.\n\n```js\nvar listener = player.on(/* ... */);\n\nplayer.off(listener);\n\n```\n\n## Polyfills\n\nNote that the built version does not inline polyfills.\n\nYou need to polyfill the environment locally (e.g. using a service such as https://polyfill.io/v2/docs/).\n\n## Examples\n\n* [Playing a video](./examples/src/playing-video/index.html).\n* [Multiple players](./examples/src/multiple-players/index.html).\n* [Registering events handlers](./examples/src/registering-event-handlers/index.html).\n\n## Debugging\n\n`youtube-player` is using [`debug`](https://www.npmjs.com/package/debug) module to expose debugging information.\n\nThe `debug` namespace is \"youtube-player\".\n\nTo display `youtube-player` logs configure `localStorage.debug`, e.g.\n\n```js\nlocalStorage.debug = 'youtube-player:*';\n\n```\n\n## Download\n\nUsing [NPM](https://www.npmjs.org/):\n\n```sh\nnpm install youtube-player\n```\n\n## Running the Examples\n\n```sh\nnpm install\nnpm run build\ncd ./examples\nnpm install\nnpm run start\n```\n\nThis will start a HTTP server on port 8000.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fyoutube-player","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgajus%2Fyoutube-player","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fyoutube-player/lists"}