|
| 1 | +# Bunny Stream |
| 2 | + |
| 3 | +> Bunny Stream is a Statamic add-on that integrates the Bunny Stream API for single stream libraries into the Statamic CP. |
| 4 | +
|
| 5 | +## Features |
| 6 | + |
| 7 | +- Upload and rename videos to Bunny Stream. |
| 8 | +- Automatically detect transcoding status. |
| 9 | +- Delete videos from Bunny Stream. |
| 10 | +- Embed videos using a custom field type or custom tag. |
| 11 | +- Customize the vidstack.io player to your needs or use your own player. |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +Install the addon using composer: |
| 16 | + |
| 17 | +```bash |
| 18 | +composer require laborb/statamic-bunny-stream |
| 19 | +``` |
| 20 | + |
| 21 | +Insert the required styles & scripts using the following tags: |
| 22 | + |
| 23 | +- Use `{{ bunny:scripts }}` to add all required javascript files. We recommend adding this to the end of the `<body>`. |
| 24 | +- Use `{{ bunny:styles }}` to add all required css files. We recommend adding this to the `<head>`. |
| 25 | + |
| 26 | +All inserted files can be configured using the configuration file. |
| 27 | + |
| 28 | +## Configuration |
| 29 | + |
| 30 | +You need to provide the following .env-Variables: |
| 31 | + |
| 32 | +```bash |
| 33 | +BUNNY_LIBRARY_ID=yourid # Your Bunny Stream LibraryID |
| 34 | +BUNNY_API_KEY=yourapikey # Your Libraries API Key |
| 35 | +BUNNY_CDN_HOSTNAME=yourcdnhostname # Your Libraries CDN Hostname |
| 36 | +``` |
| 37 | + |
| 38 | +You can find these values in your Bunny Stream Dashboard at [https://dash.bunny.net/stream/](https://dash.bunny.net/stream/) `Delivery > Stream > API` |
| 39 | + |
| 40 | +You can enable Video embedding by setting the following variables: |
| 41 | + |
| 42 | +```bash |
| 43 | +BUNNY_EMBED_PATH="yourpath" |
| 44 | +BUNNY_EMBED_DOMAIN="*" |
| 45 | +``` |
| 46 | + |
| 47 | +All videos will then be available through a direct url. Check the video browser to get the correct url for each video. |
| 48 | + |
| 49 | +Using `BUNNY_EMBED_DOMAIN` you can change the Access Control Header, if you want to limit access. |
| 50 | + |
| 51 | +### Custom CDN Hostname |
| 52 | + |
| 53 | +To add a custom hostname you can do the following: |
| 54 | + |
| 55 | +1. Login to your bunny dashboard and head over to `Delivery > Stream > API` |
| 56 | +2. At Pull zone click `Manage` |
| 57 | +3. Create a CName entry in your DNS settings pointing to the displayed bunny CDN hostname |
| 58 | +4. Enter your custom hostname in the bunny settings and activate SSL |
| 59 | +5. Use your custom hostname in the .env `BUNNY_CDN_HOSTNAME=yourcdnhostname` |
| 60 | + |
| 61 | +Now your videos are delivered over your custom hostname. |
| 62 | + |
| 63 | +### Publish Configuration (optional) |
| 64 | + |
| 65 | +After installing the addon you can publish and update the default configuration: |
| 66 | + |
| 67 | +```bash |
| 68 | +php artisan vendor:publish --tag=bunny-config |
| 69 | +``` |
| 70 | + |
| 71 | +### Publish Views (optional) |
| 72 | + |
| 73 | +All views are completely customizable. To publish them use: |
| 74 | + |
| 75 | +```bash |
| 76 | +php artisan vendor:publish --tag=bunny-views |
| 77 | +``` |
| 78 | + |
| 79 | +## Usage |
| 80 | + |
| 81 | +The bunny tag allows you to display a Bunny video stream using the Vidstack player in your Statamic site. |
| 82 | + |
| 83 | +```antlers |
| 84 | +{{ bunny id="bunny-video-id" title="My Video" poster="https://example.com/poster.jpg" preload="auto" class="custom-class" tracks="{{ tracks }}" }} |
| 85 | +``` |
| 86 | + |
| 87 | +### Parameters |
| 88 | + |
| 89 | +| Parameter | Type | Description | |
| 90 | +|-----------|-------------------|--------------------------------------------------------------------------------------------------| |
| 91 | +| `id` | string | The id of the video you want to display. | |
| 92 | +| `title` | string (optional) | A title to display for the video. Defaults to `null`. | |
| 93 | +| `poster` | string (optional) | A poster image URL to display before the video starts. Defaults to `null`. | |
| 94 | +| `width` | int (optional) | The width of the video. Defaults to `null`. | |
| 95 | +| `height` | int (optional) | The height of the video. Defaults to `null`. | |
| 96 | +| `preload` | string (optional) | How the video should be preloaded. Options: `auto`, `metadata`, `none`. Defaults to `metadata`. | |
| 97 | +| `tracks` | array (optional) | An array of additional tracks (e.g., captions, subtitles). Defaults to `[]`. | |
| 98 | +| `class` | string (optional) | Additional HTML classes to be added to the wrapper. | |
| 99 | + |
| 100 | +### Configuring Tracks Array |
| 101 | + |
| 102 | +The `tracks` parameter must be formatted as an array of objects, where each object represents a caption or subtitle |
| 103 | +track. The structure follows loosely the [Vidstack track format](https://vidstack.io/docs/wc/player/api/text-tracks/): |
| 104 | + |
| 105 | +Each track object must include the following properties: |
| 106 | + |
| 107 | +- `source`: The URL of the caption file. |
| 108 | +- `kind`: The type of track, e.g., `subtitles`, `captions`, `descriptions`. |
| 109 | +- `language`: The language code, e.g., `en`, `es`, `fr`. |
| 110 | +- `label`: The visible label for the track. |
| 111 | + |
| 112 | +Example JSON configuration for tracks: |
| 113 | + |
| 114 | +```json |
| 115 | +[ |
| 116 | + { "source": "/path/to/captions-en.vtt", "kind": "subtitles", "language": "en", "label": "English" }, |
| 117 | + { "source": "/path/to/captions-es.vtt", "kind": "subtitles", "language": "es", "label": "Spanish" } |
| 118 | +] |
| 119 | +``` |
| 120 | + |
| 121 | +### Bunny-Field & -Fieldset |
| 122 | + |
| 123 | +This addon includes a basic Bunny fieldset that you can use. |
| 124 | + |
| 125 | +When using the fieldset you can use the following markup to output the video player: |
| 126 | + |
| 127 | +```antlers |
| 128 | +{{ bunny :id="bunny_video" :poster="bunny_poster[0]" :controls="bunny_controls" :tracks="bunny_captions" }} |
| 129 | +``` |
| 130 | + |
| 131 | +You can also just use the Bunny field by adding it to any blueprint. |
| 132 | + |
| 133 | +## Customization |
| 134 | + |
| 135 | +You can customize the video player to your needs. |
| 136 | +Check the [vidstack.io](https://vidstack.io/docs/wc/player) documentation for details. |
0 commit comments