- Implemented audio support with Video.js.
What changed: Added uploaded/direct audio playback paths in [index.php](/Users/tyemeclifford/Documents/GH/mediaplayer/index.php) and [embed.php](/Users/tyemeclifford/Documents/GH/mediaplayer/embed.php). Added common audio upload support: MP3, M4A, AAC, WAV, FLAC, OGG, OGA, OPUS. Added waveform poster generation for uploaded audio via ffmpeg, stored like normal thumbnails under media/thumbs/. Updated add/edit forms to accept media files, not just video files. Added audio-friendly labels like Audio, 320kbps, 256kbps, 128kbps. Updated docs and changelog.
This commit is contained in:
+22
-14
@@ -94,7 +94,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if ($source_type === 'remote') {
|
||||
$source_url = normalize_media_url($upd_urls[$i] ?? '');
|
||||
if ($source_url === '') {
|
||||
$error = 'External video URLs must start with http:// or https://.';
|
||||
$error = 'External media URLs must start with http:// or https://.';
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$new_files = $_FILES['new_source_file'] ?? [];
|
||||
$videos_dir = MEDIA_DIR . 'videos/';
|
||||
if (!is_dir($videos_dir)) mkdir($videos_dir, 0755, true);
|
||||
$allowed_video = ['mp4','webm','ogv','ogg','mov','mkv','avi'];
|
||||
$allowed_media = media_allowed_upload_extensions();
|
||||
|
||||
$new_count = max(
|
||||
count($new_types),
|
||||
@@ -147,7 +147,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if ($type === 'remote') {
|
||||
$url = normalize_media_url($new_urls[$i] ?? '');
|
||||
if ($url === '') {
|
||||
if (trim($new_urls[$i] ?? '') !== '') $error = 'External video URLs must start with http:// or https://.';
|
||||
if (trim($new_urls[$i] ?? '') !== '') $error = 'External media URLs must start with http:// or https://.';
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -163,14 +163,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (empty($tmp) || !is_uploaded_file($tmp)) continue;
|
||||
$orig = $new_files['name'][$i] ?? '';
|
||||
$ext = strtolower(pathinfo($orig, PATHINFO_EXTENSION));
|
||||
if (!in_array($ext, $allowed_video, true)) continue;
|
||||
if (!in_array($ext, $allowed_media, true)) {
|
||||
$error = 'Uploaded media files must be one of: ' . media_upload_format_summary() . '.';
|
||||
break;
|
||||
}
|
||||
$fname = $slug . '_' . time() . '_' . $i . '.' . $ext;
|
||||
if (move_uploaded_file($tmp, $videos_dir . $fname)) {
|
||||
$moved_files[] = $videos_dir . $fname;
|
||||
$target = $videos_dir . $fname;
|
||||
$moved_files[] = $target;
|
||||
$db->prepare("
|
||||
INSERT INTO video_sources (video_id, label, source_type, file_path, source_url, mime_type, quality, sort_order)
|
||||
VALUES (?,?,?,?,?,?,?,?)
|
||||
")->execute([$id, $label, 'local', 'videos/' . $fname, '', mime_from_ext($fname), $quality, $sort]);
|
||||
")->execute([$id, $label, 'local', 'videos/' . $fname, '', media_mime_from_local_file($target, $fname), $quality, $sort]);
|
||||
$inserted_source_ids[] = (int)$db->lastInsertId();
|
||||
}
|
||||
}
|
||||
@@ -278,7 +282,7 @@ render_head('Edit Video — Admin', '
|
||||
</a>
|
||||
<a href="add.php">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/></svg>
|
||||
Add Video
|
||||
Add Media
|
||||
</a>
|
||||
<a href="youtube_import.php">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22.54 6.42a2.78 2.78 0 00-1.95-2C18.88 4 12 4 12 4s-6.88 0-8.59.46a2.78 2.78 0 00-1.95 2A29 29 0 001 12a29 29 0 00.46 5.58 2.78 2.78 0 001.95 2C5.12 20 12 20 12 20s6.88 0 8.59-.46a2.78 2.78 0 001.95-2A29 29 0 0023 12a29 29 0 00-.46-5.58z"/><polygon points="10,15 15,12 10,9"/></svg>
|
||||
@@ -305,7 +309,7 @@ render_head('Edit Video — Admin', '
|
||||
|
||||
<!-- ── Details ── -->
|
||||
<div class="card" style="margin-bottom:1rem;">
|
||||
<p class="section-heading">Video Details</p>
|
||||
<p class="section-heading">Media Details</p>
|
||||
<div class="form-grid">
|
||||
<div class="form-group span2">
|
||||
<label class="form-label" for="title">Title *</label>
|
||||
@@ -359,9 +363,9 @@ render_head('Edit Video — Admin', '
|
||||
accept="image/jpeg,image/png,image/webp,image/gif" style="padding:.45rem .6rem;">
|
||||
<label style="display:flex;align-items:center;gap:.55rem;margin-top:.55rem;cursor:pointer;">
|
||||
<input type="checkbox" name="auto_thumbnail" value="1" <?= isset($_POST['auto_thumbnail']) || ($_SERVER['REQUEST_METHOD'] !== 'POST' && !$video['thumbnail']) ? 'checked' : '' ?>>
|
||||
<span style="font-size:.78rem;color:var(--text-2);">Auto-grab/refresh thumbnail from source on save</span>
|
||||
<span style="font-size:.78rem;color:var(--text-2);">Auto-grab/refresh thumbnail or waveform from source on save</span>
|
||||
</label>
|
||||
<span class="hint">Upload a new image to override auto-grab. Auto-grab supports YouTube, Vimeo, Dailymotion and other oEmbed providers; local uploads use ffmpeg when available.</span>
|
||||
<span class="hint">Upload a new image to override auto-grab. Auto-grab supports providers, local video first frames, and local audio waveforms when ffmpeg is available.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -402,7 +406,7 @@ render_head('Edit Video — Admin', '
|
||||
<div class="form-group">
|
||||
<label class="form-label">Quality</label>
|
||||
<select class="form-select" name="src_quality[]">
|
||||
<?php foreach (['1080p','720p','480p','360p','4K',''] as $q): ?>
|
||||
<?php foreach (['1080p','720p','480p','360p','4K','Audio','320kbps','256kbps','128kbps',''] as $q): ?>
|
||||
<option value="<?= $q ?>" <?= $s['quality']===$q ? 'selected' : '' ?>><?= $q ?: '—' ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
@@ -425,7 +429,7 @@ render_head('Edit Video — Admin', '
|
||||
<!-- ── Add new sources ── -->
|
||||
<div class="card" style="margin-bottom:1rem;">
|
||||
<p class="section-heading">Add New Sources</p>
|
||||
<p class="hint" style="margin-bottom:.85rem;">Upload another file, link a direct media file, or paste a provider page URL such as YouTube or Vimeo.</p>
|
||||
<p class="hint" style="margin-bottom:.85rem;">Upload another video or audio file, link a direct media file, or paste a provider page URL such as YouTube or Vimeo. Uploaded files: <strong><?= h(media_upload_format_summary()) ?></strong>.</p>
|
||||
<div class="source-list" id="new-sources-container">
|
||||
<div class="add-source-row" data-new-row="0">
|
||||
<div class="form-group">
|
||||
@@ -436,9 +440,9 @@ render_head('Edit Video — Admin', '
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group source-location-panel source-location-local">
|
||||
<label class="form-label">Video File</label>
|
||||
<label class="form-label">Media File</label>
|
||||
<input class="form-input" type="file" name="new_source_file[]"
|
||||
accept="video/mp4,video/webm,video/ogg,.mp4,.webm,.ogv,.mov,.mkv,.avi"
|
||||
accept="<?= h(media_upload_accept_attribute()) ?>"
|
||||
style="padding:.45rem .6rem;">
|
||||
</div>
|
||||
<div class="form-group source-location-panel source-location-remote" hidden>
|
||||
@@ -453,6 +457,10 @@ render_head('Edit Video — Admin', '
|
||||
<option value="480p">480p</option>
|
||||
<option value="360p">360p</option>
|
||||
<option value="4K">4K</option>
|
||||
<option value="Audio">Audio</option>
|
||||
<option value="320kbps">320kbps</option>
|
||||
<option value="256kbps">256kbps</option>
|
||||
<option value="128kbps">128kbps</option>
|
||||
<option value="">—</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user