html<!-- Load the library -->
<script src="https://cdn.mediathrive.com/js/mediakit.js"></script>
<!-- Add player container -->
<div data-mediathrive>
<div class="mediakit-audio-player"></div>
<div class="mediakit-video-player"></div>
</div>
The script automatically calculates the correct manifest URL for the current page and loads it. If the URL returns 404, no player is shown.
Attribute | Purpose | Default | Values |
---|---|---|---|
data-mediathrive | Required - Marks element as MediaKit player | — | Present/absent |
data-manifest | Override auto-detected manifest URL | Auto-generated | URL string |
data-demo | Load random demo content for testing | Off | Present/absent |
data-log-level | Console log verbosity | INFO | ERROR , WARN , INFO , DEBUG (or 0-3) |
Attribute | Purpose | Default |
---|---|---|
data-audio-div | Class name for audio player container | mediakit-audio-player |
data-video-div | Class name for video player container | mediakit-video-player |
data-videosrc | Direct video URL (bypass manifest) | — |
Attribute | Purpose | Default |
---|---|---|
data-ads | Enable ads (must be "true" to activate) | Disabled |
data-ad-tag | Custom VAST ad tag URL | Auto-generated |
data-ad-account | Google Ad Manager account ID | MediaThrive's Ad account |
data-description-url | URL for ad targeting | Current page URL |
html<div
data-mediathrive
data-manifest="https://cdn.mediathrive.com/custom/manifest.json"
data-log-level="DEBUG"
data-ads="true"
data-ad-account="12345678,87654321"
data-description-url="https://example.com/article"
data-audio-div="custom-audio-container"
data-video-div="custom-video-container"
>
<div class="custom-audio-container"></div>
<div class="custom-video-container"></div>
</div>
window.MTMediaKit
Method | Description | Parameters |
---|---|---|
init(options?) | Initialize all players | {logLevel?: number} |
autoInit(options?) | Auto-init when DOM ready | {logLevel?: number} |
setLogLevel(level) | Set global log level | LOG_LEVELS constant or 0-3 |
parseLogLevel(str) | Parse log level from string | String: "ERROR" , "WARN" , etc. |
Method | Description | Returns |
---|---|---|
getInstance(id) | Get specific player instance | Player object |
getAllInstances() | Get all player instances | Object map |
reinitialize(id, attrs) | Reinitialize specific player | void |
reinitializeAll() | Reinitialize all players | void |
cleanup(id) | Destroy specific player | void |
cleanupAll() | Destroy all players | void |
javascriptMTMediaKit.LOG_LEVELS = {
ERROR: 0,
WARN: 1,
INFO: 2,
DEBUG: 3
}
Once you have a player instance via getInstance()
:
javascriptconst player = MTMediaKit.getInstance('player-id');
player.play(episode); // Play specific episode
player.pause(); // Pause playback
player.toggle(episode); // Toggle play/pause
player.seek(timeInSeconds); // Seek to position
player.seekBy(seconds); // Seek forward/backward
player.playbackRate(rate); // Set speed (0.5, 1.0, 1.25, 1.5, 2.0)
javascriptplayer.toggleMute(); // Toggle mute
player.isPlaying(episode); // Check if playing
player.changeSource(newAudio); // Change source
player.setAutoplayEnabled(bool); // Enable/disable autoplay
player.clearAutoplayError(); // Clear autoplay error
javascriptplayer.openPlaylist(); // Open playlist
player.togglePlaylist(); // Toggle playlist visibility
Event | Description | Detail Properties |
---|---|---|
audio-started | Playback started | playerId , src , uuid , metadata , currentTime , duration |
audio-paused | Playback paused | Same as above |
audio-ended | Playback completed | Same as above |
audio-autoplay-blocked | Autoplay blocked | playerId , error |
Event | Description |
---|---|
audio-progress | Fires every 10% |
audio-progress-0 through audio-progress-100 | Specific milestones |
Event | Description | Detail Properties |
---|---|---|
ad-started | Ad playback started | playerId , adTitle |
ad-ended | Ad playback ended | playerId |
ad-error | Ad error occurred | playerId , error |
ad-preroll-started | Pre-roll ad started | playerId |
ad-preroll-completed | Pre-roll ad completed | playerId |
ad-clicked | Ad was clicked | playerId |
javascript// Using MediaPlayerManager
const manager = MediaPlayerManager.getInstance();
manager.on('audio-started', (event) => {
console.log('Audio started:', event.detail);
});
// Using DOM events
document.addEventListener('audio-progress', (e) => {
console.log(`Progress: ${e.detail.progress}%`);
});
MediaKit supports 35 languages with automatic detection and CDN-based loading:
The language is automatically detected from the domain's theme configuration. Translations are loaded from:
https://cdn.mediathrive.com/sdk/translation/{language}.json
MediaKit includes a sophisticated theming system that adapts to different domains:
javascript{
domain: "example.com",
logos: {
primary: "https://cdn.example.com/logo.png"
},
colors: {
primary: "#0000FF",
accent: "#00FF00"
},
language: "en-US",
features: {
podcast: true // Enable podcast features
}
}
MediaKit includes built-in analytics:
javascript{
event: "play|pause|start|auto_percent|session_end",
team_account_id: "12345",
media: "audio-uuid",
url_hash: "page-hash",
media_type: "audio",
percent: "25" // For progress events
}
html<!-- Enable ads with default settings -->
<div data-mediathrive data-ads="true">
<div class="mediakit-audio-player"></div>
</div>
<!-- Custom ad configuration -->
<div
data-mediathrive
data-ads="true"
data-ad-account="your-account-id"
data-ad-tag="https://your-vast-url.com"
>
<div class="mediakit-audio-player"></div>
</div>
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MediaKit Complete Example</title>
<script src="https://cdn.mediathrive.com/js/mediakit.js"></script>
</head>
<body>
<h1>MediaKit Examples</h1>
<!-- Basic Player -->
<div data-mediathrive data-manifest="https://example.com/manifest.json">
<div class="mediakit-audio-player"></div>
</div>
<!-- Player with Ads -->
<div
data-mediathrive
data-ads="true"
data-log-level="DEBUG"
>
<div class="mediakit-audio-player"></div>
</div>
<!-- Player with Custom Configuration -->
<div
data-mediathrive
data-ads="true"
data-ad-account="12345678"
data-log-level="INFO"
>
<div class="mediakit-audio-player"></div>
<div class="mediakit-video-player"></div>
</div>
<script>
// Access the global API
const MT = window.MTMediaKit;
// Set log level
MT.setLogLevel(MT.LOG_LEVELS.DEBUG);
// Listen to events
document.addEventListener('audio-started', (e) => {
console.log('Audio started:', e.detail);
// Access player instance
const player = MT.getInstance(e.detail.playerId);
// Control playback
setTimeout(() => {
player.playbackRate(1.5); // Speed up
}, 5000);
});
// Track progress
document.addEventListener('audio-progress', (e) => {
console.log(`Progress: ${e.detail.progress}%`);
});
// Handle ads
document.addEventListener('ad-started', (e) => {
console.log('Ad playing:', e.detail);
});
</script>
</body>
</html>
MediaKit uses JSON manifests to define content. Here's the complete structure:
json{
"audio": {
"en": {
"src": "https://example.com/audio-en.mp3",
"type": "audio/mpeg",
"uuid": "unique-audio-id",
"language": "en-US",
"title": "Episode Title",
"description": "Episode description"
},
"es": {
"src": "https://example.com/audio-es.mp3",
"type": "audio/mpeg",
"uuid": "unique-audio-id-es",
"language": "es-ES"
}
},
"video": {
"src": "https://example.com/video.m3u8",
"type": "application/x-mpegURL",
"poster": "https://example.com/poster.jpg"
},
"metadata": {
"title": "Article Title",
"author": "Author Name",
"publicationDate": "2024-01-01",
"description": "Article description",
"url": "https://example.com/article"
},
"suggestion": {
"title": "Next Article Title",
"url": "https://example.com/next-article"
}
}
All MediaKit styles are namespaced under [data-mediathrive]
:
css[data-mediathrive] {
/* Your custom styles */
--mt-primary-color: #0066cc;
--mt-accent-color: #00aa66;
}
[data-mediathrive] .mediakit-audio-player {
/* Audio player specific styles */
}
Internal components use Tailwind with mtk:
prefix to avoid conflicts:
mtk:flex
mtk:bg-white
mtk:text-sm
Required CSP directives:
html<meta http-equiv="Content-Security-Policy" content="
script-src 'self' https://cdn.mediathrive.com https://imasdk.googleapis.com;
connect-src 'self' https://cdn.mediathrive.com https://pubads.g.doubleclick.net;
media-src *;
img-src *;
">
Access-Control-Allow-Origin
✓ Verify data-mediathrive
attribute is present
✓ Check browser console for errors
✓ Confirm manifest URL returns valid JSON (404 is OK if no content)
✓ Check log level for debugging info
✓ Verify media URLs in manifest are accessible
✓ Check CORS headers for cross-domain content
✓ Confirm correct MIME types for media files
✓ Test with data-demo
for known working content
✓ Ensure data-ads="true"
is set (ads are off by default)
✓ Check browser console for IMA SDK errors
✓ Verify ad account has valid campaigns
✓ Test with default account first
✓ Browser policies may block autoplay
✓ MediaKit shows permission prompt automatically
✓ User interaction required for first play
✓ Use CSS namespacing under [data-mediathrive]
✓ Check for conflicting global styles
✓ Tailwind classes use mtk:
prefix
✓ Check theme configuration for language setting
✓ Verify translation file exists on CDN
✓ Falls back to English if translation missing
data-use-default-ads
to data-ads
MediaThrive
to MTMediaKit
data-mediathrive
data-demo
firstjavascript// Initialize
MTMediaKit.init();
// Get player
const player = MTMediaKit.getInstance('player-id');
// Control playback
player.play();
player.pause();
player.seek(30);
// Listen to events
document.addEventListener('audio-started', handler);
document.addEventListener('audio-progress', handler);
html<!-- Basic -->
<div data-mediathrive data-manifest="url.json"></div>
<!-- With ads -->
<div data-mediathrive data-ads="true"></div>
<!-- Debug mode -->
<div data-mediathrive data-log-level="DEBUG"></div>
<!-- Demo content -->
<div data-mediathrive data-demo></div>
Last Updated: August 2025
Version: 2.0.0
License: Proprietary - MediaThrive Inc.
Happy streaming with MediaKit! 🎵 📺