| 1447 | } |
| 1448 | |
| 1449 | static removeMediaPlayer (type: string, key?: string): void { |
| 1450 | const players = this.mediaPlayers (type, true) as Record<string, HTMLAudioElement | HTMLVideoElement | AudioPlayer> | undefined; |
| 1451 | |
| 1452 | const cleanupPlayer = (player: HTMLAudioElement | HTMLVideoElement | AudioPlayer): void => { |
| 1453 | if (player instanceof AudioPlayer) { |
| 1454 | // Use AudioPlayer's destroy method which handles cleanup properly |
| 1455 | player.destroy(); |
| 1456 | } else { |
| 1457 | // Handle HTMLAudioElement/HTMLVideoElement |
| 1458 | if (typeof player.pause === 'function') { |
| 1459 | player.pause(); |
| 1460 | } |
| 1461 | if (typeof player.setAttribute === 'function') { |
| 1462 | player.setAttribute('src', ''); |
| 1463 | player.currentTime = 0; |
| 1464 | } |
| 1465 | } |
| 1466 | }; |
| 1467 | |
| 1468 | if (typeof key === 'undefined') { |
| 1469 | if (players) { |
| 1470 | for (const mediaKey of Object.keys(players)) { |
| 1471 | const player = this._mediaPlayers[type][mediaKey]; |
| 1472 | if (player) { |
| 1473 | cleanupPlayer(player); |
| 1474 | } |
| 1475 | delete this._mediaPlayers[type][mediaKey]; |
| 1476 | } |
| 1477 | } |
| 1478 | } else { |
| 1479 | if (typeof this._mediaPlayers[type]?.[key] !== 'undefined') { |
| 1480 | const player = this._mediaPlayers[type][key]; |
| 1481 | if (player) { |
| 1482 | cleanupPlayer(player); |
| 1483 | } |
| 1484 | delete this._mediaPlayers[type][key]; |
| 1485 | } |
| 1486 | } |
| 1487 | } |
| 1488 | |
| 1489 | static temp (key: string, value?: unknown): unknown { |
| 1490 | if (typeof value !== 'undefined') { |