Socket
Socket
Sign inDemoInstall

svelte-youtube

Package Overview
Dependencies
6
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    svelte-youtube

Simple [Svelte](https://svelte.dev/) component acting as a thin layer over the [YouTube IFrame Player API](https://developers.google.com/youtube/iframe_api_reference). Based on [react-youtube](https://github.com/tjallingt/react-youtube).


Version published
Weekly downloads
183
increased by56.41%
Maintainers
1
Install size
167 kB
Created
Weekly downloads
 

Changelog

Source

[0.0.2] - 2020-12-10

Added

  • Added support for prop and autoplay options
  • Added CHANGELOG

Readme

Source

svelte-youtube

Simple Svelte component acting as a thin layer over the YouTube IFrame Player API. Based on react-youtube.

Features

Installation

$ npm install svelte-youtube

Usage

<script>
  import YouTube from 'svelte-youtube';
</script>

<YouTube
  videoId={string}                  // defaults -> null
  id={string}                       // defaults -> null
  class={string}                    // defaults -> null
  options={obj}                     // defaults -> {}
/>

Events

The following events are available:

  • on:ready: Player has finished loading and is ready to play
  • on:play: Playback has started
  • on:pause: Playback has been paused
  • on:end: Playback has ended
  • on:error: An error has occurred (see below)
  • on:stateChange: Player State has changed (see below)
  • on:playbackRateChange: Playback rate has changed (see below)
  • on:playbackQualityChange: Playback quality has changed (see below)

Each event's detail property contains a data and a target property (except for the ready event, which does not have a data property). The target is a reference to the player instance, while the data contains information specific to the event.

For details on the contents of the data property, and for a more detailed description of each event, refer to the YouTube IFrame Player API Events .

Player State

For convenience it is also possible to access the PlayerState constants through svelte-youtube.

The PlayerState named export contains the values that are used by the YouTube IFrame Player API.

Player Errors

Refer to YouTube IFrame Player API for an explanation of the error codes used in the on:error event.

Controlling the player

Each of the component's events contains a target property in the event's detail object. This property contains a reference to the underlying player instance. Once you have an instance of the player object, you may call any of the available functions on it.

Example

<script>
  import YouTube from 'svelte-youtube';

  const options = {
    height: '390',
    width: '640',
    //  see https://developers.google.com/youtube/player_parameters
    playerVars: {
      autoplay: 1
    }
  };

  function onReady(event) {
    // access to player in all event handlers via event.target
    event.target.pauseVideo();
  }
</script>

<YouTube videoId="2g811Eo7K8U" {options} on:ready={onReady} />

License

MIT

Keywords

FAQs

Last updated on 10 Dec 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc