fix download
This commit is contained in:
parent
dbebdf79fd
commit
b2e61129d8
@ -88,7 +88,7 @@ class SimpleAudioPlayer {
|
||||
this.audio.currentTime = this.timeline.value;
|
||||
|
||||
// immediate Android sync
|
||||
if (navigator.mediaSession?.setPositionState) {
|
||||
if (navigator.mediaSession?.setPositionState && Number.isFinite(this.audio.duration)) {
|
||||
navigator.mediaSession.setPositionState({
|
||||
duration: this.audio.duration,
|
||||
playbackRate: this.audio.playbackRate,
|
||||
@ -129,7 +129,7 @@ class SimpleAudioPlayer {
|
||||
this.timeInfo.textContent =
|
||||
`${this._formatTime(this.audio.currentTime)} / ${this._formatTime(this.audio.duration)}`;
|
||||
// 4) Push to Android widget
|
||||
if (navigator.mediaSession?.setPositionState) {
|
||||
if (navigator.mediaSession?.setPositionState && Number.isFinite(this.audio.duration)) {
|
||||
navigator.mediaSession.setPositionState({
|
||||
duration: this.audio.duration,
|
||||
playbackRate: this.audio.playbackRate,
|
||||
@ -138,6 +138,26 @@ class SimpleAudioPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
async fileDownload() {
|
||||
const src = this.audio.currentSrc || this.audio.src;
|
||||
if (!src) return;
|
||||
|
||||
// Build the URL with your download flag + cache‑buster
|
||||
const downloadUrl = new URL(src, window.location.href);
|
||||
downloadUrl.searchParams.set('download', 'true');
|
||||
downloadUrl.searchParams.set('_', Date.now());
|
||||
|
||||
// Create a “real” link to that URL and click it
|
||||
const a = document.createElement('a');
|
||||
a.href = downloadUrl.toString();
|
||||
a.download = ''; // tell Safari “this is a download”
|
||||
a.target = '_blank'; // force a real navigation on iOS
|
||||
// NOTE: do NOT set a.download here – we want the server's Content-Disposition to drive it
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
}
|
||||
|
||||
async loadTrack(relUrl) {
|
||||
this.audio.pause();
|
||||
this.container.style.display = 'block';
|
||||
@ -159,9 +179,9 @@ class SimpleAudioPlayer {
|
||||
// Full breadcrumb
|
||||
const parts = relUrl.split('/');
|
||||
const file = parts.pop();
|
||||
const folderPath = parts.join(' › ');
|
||||
const folderPath = parts.join(' › ').replace('Gottesdienste S','S'); // Special case
|
||||
this.nowInfo.innerHTML =
|
||||
`${folderPath} › <strong>${file.replace(/\.[^/.]+$/, '')}</strong>`;
|
||||
`${folderPath}<br><strong>${file.replace(/\.[^/.]+$/, '')}</strong>`;
|
||||
|
||||
if ('mediaSession' in navigator) {
|
||||
navigator.mediaSession.metadata = new MediaMetadata({
|
||||
@ -222,7 +242,7 @@ class SimpleAudioPlayer {
|
||||
|
||||
// Heartbeat for widget
|
||||
this._posInterval = setInterval(() => {
|
||||
if (!this.audio.paused && navigator.mediaSession.setPositionState) {
|
||||
if (!this.audio.paused && navigator.mediaSession?.setPositionState && Number.isFinite(this.audio.duration)) {
|
||||
navigator.mediaSession.setPositionState({
|
||||
duration: this.audio.duration,
|
||||
playbackRate: this.audio.playbackRate,
|
||||
|
||||
@ -204,7 +204,7 @@
|
||||
<input type="range" class="timeline" max="100" value="0" step="0.1">
|
||||
<div id="timeInfo" class="now-playing-info"></div>
|
||||
</div>
|
||||
<button class="sound-button icon-color" onclick="downloadAudio()">
|
||||
<button class="sound-button icon-color" onclick="player.fileDownload()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 122.88 120.89" width="35" height="35">
|
||||
<path fill-rule="evenodd" d="M84.58,47a7.71,7.71,0,1,1,10.8,11L66.09,86.88a7.72,7.72,0,0,1-10.82,0L26.4,58.37a7.71,7.71,0,1,1,10.81-11L53.1,63.12l.16-55.47a7.72,7.72,0,0,1,15.43.13l-.15,55L84.58,47ZM0,113.48.1,83.3a7.72,7.72,0,1,1,15.43.14l-.07,22q46,.09,91.91,0l.07-22.12a7.72,7.72,0,1,1,15.44.14l-.1,30h-.09a7.71,7.71,0,0,1-7.64,7.36q-53.73.1-107.38,0A7.7,7.7,0,0,1,0,113.48Z"/>
|
||||
</svg>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user