> For the complete documentation index, see [llms.txt](https://bonsai-docs.gitbook.io/bonsai-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bonsai-docs.gitbook.io/bonsai-docs/bonsai-radio/configuration/advertisements.md).

# Advertisements

## Advertisement Configuration

Bonsai Radio supports both **global advertisements** and **station-specific advertisements**.

Advertisement settings are configured in:

```
config.lua
```

***

## Global Advertisement Settings

```lua
Config.RadioAds = {
    enabled = true,

    globalAds = {
        {
            file = 'audio/ads/global/ammunation.ogg',
            title = 'Commercial Break',
            artist = 'Ammunation',
            cover = ''
        }
    }
}
```

### enabled

```lua
enabled = true
```

Master switch for all advertisements and advertisement jingles.

| Value   | Description                               |
| ------- | ----------------------------------------- |
| `true`  | Advertisements and jingles are available. |
| `false` | Disables all advertisements and jingles.  |

***

### globalAds

```lua
globalAds = {
    {
        file = 'audio/ads/global/example.ogg',
        title = 'Commercial Break',
        artist = 'Advertisement',
        cover = ''
    }
}
```

Advertisements added here can be used by every station with:

```lua
useGlobalAds = true
```

Leaving the global advertisement list empty is completely valid.

***

## Advertisement Entry

Each advertisement can contain the following settings:

### file

```lua
file = 'audio/ads/global/example.ogg'
```

Path to the advertisement audio file.

MP3 and OGG are supported.

***

### title

```lua
title = 'Commercial Break'
```

Text displayed as the advertisement title.

***

### artist

```lua
artist = 'Advertisement'
```

Text displayed underneath the title.

This can also be used for the business or sponsor name.

***

### cover

```lua
cover = 'images/covers/example.jpg'
```

Optional artwork displayed while the advertisement is playing.

Leave it empty to use the station icon:

```lua
cover = ''
```

***

## Station Advertisement Settings

Every station has its own advertisement configuration:

```lua
ads = {
    enabled = false,
    minSongs = 3,
    maxSongs = 6,
    chance = 100,
    useGlobalAds = true,
    useStationAds = true,
    stationAds = {},
    jinglesBefore = {},
    jinglesAfter = {}
}
```

***

### enabled

```lua
enabled = true
```

Enables advertisement breaks for this station.

If disabled, the station will not play advertisements or advertisement jingles.

***

### minSongs

```lua
minSongs = 3
```

Minimum number of completed songs before an advertisement opportunity.

***

### maxSongs

```lua
maxSongs = 6
```

Maximum number of completed songs before an advertisement opportunity.

The script selects a random number between `minSongs` and `maxSongs`.

Example:

```lua
minSongs = 3,
maxSongs = 6
```

An advertisement opportunity will occur after between three and six completed songs.

***

### chance

```lua
chance = 100
```

Percentage chance that an advertisement plays when the song threshold is reached.

| Value | Description                 |
| ----- | --------------------------- |
| `100` | Advertisement always plays. |
| `75`  | 75% chance.                 |
| `50`  | 50% chance.                 |
| `0`   | Advertisement never plays.  |

***

### useGlobalAds

```lua
useGlobalAds = true
```

Allows the station to use advertisements from:

```lua
Config.RadioAds.globalAds
```

Set this to `false` when the station should not use global advertisements.

***

### useStationAds

```lua
useStationAds = true
```

Allows the station to use advertisements from its own:

```lua
stationAds
```

Set this to `false` when the station should only use global advertisements.

***

### stationAds

```lua
stationAds = {
    {
        file = 'audio/ads/stations/example.ogg',
        title = 'Commercial Break',
        artist = 'Advertisement',
        cover = ''
    }
}
```

Advertisements added here are exclusive to that station.

***

## Global Advertisements Only

```lua
ads = {
    enabled = true,
    minSongs = 3,
    maxSongs = 6,
    chance = 100,
    useGlobalAds = true,
    useStationAds = false,
    stationAds = {},
    jinglesBefore = {},
    jinglesAfter = {}
}
```

***

## Station Advertisements Only

```lua
ads = {
    enabled = true,
    minSongs = 3,
    maxSongs = 6,
    chance = 100,
    useGlobalAds = false,
    useStationAds = true,

    stationAds = {
        {
            file = 'audio/ads/stations/example.ogg',
            title = 'Commercial Break',
            artist = 'Advertisement',
            cover = ''
        }
    },

    jinglesBefore = {},
    jinglesAfter = {}
}
```

***

## Global and Station Advertisements

```lua
useGlobalAds = true,
useStationAds = true
```

The station can select advertisements from both pools.

***

## Disable Advertisements for a Station

```lua
ads = {
    enabled = false,
    minSongs = 3,
    maxSongs = 6,
    chance = 100,
    useGlobalAds = true,
    useStationAds = true,
    stationAds = {},
    jinglesBefore = {},
    jinglesAfter = {}
}
```

The station will continue playing music without commercial breaks.

***

## Applying Changes

After adding or removing advertisement audio files, run:

```
auto_media_scanner.bat
```

Then restart Bonsai Radio:

```
restart rs_radio
```

The scanner reads the exact advertisement durations and stores them in:

```
data/media_library.json
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://bonsai-docs.gitbook.io/bonsai-docs/bonsai-radio/configuration/advertisements.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
