unified-video-framework 1.4.255 → 1.4.256

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1574,52 +1574,138 @@ export class WebPlayer extends BasePlayer {
1574
1574
  this.debugWarn('setPlaybackQuality failed:', e);
1575
1575
  }
1576
1576
 
1577
- // Method 3: Force quality by pausing and resuming (more aggressive)
1577
+ // Method 3: Force quality with seekTo trick (most aggressive)
1578
1578
  try {
1579
+ const currentTime = this.youtubePlayer.getCurrentTime();
1579
1580
  const wasPlaying = this.youtubePlayer.getPlayerState() === window.YT.PlayerState.PLAYING;
1580
- if (wasPlaying) {
1581
- this.youtubePlayer.pauseVideo();
1581
+
1582
+ // Seek to current time + 0.1 seconds to force reload with new quality
1583
+ this.youtubePlayer.seekTo(currentTime + 0.1, true);
1584
+
1585
+ // Set quality immediately after seek
1586
+ setTimeout(() => {
1587
+ this.youtubePlayer.setPlaybackQuality(qualityLevel);
1588
+
1589
+ // Seek back to original time
1582
1590
  setTimeout(() => {
1583
- this.youtubePlayer.setPlaybackQuality(qualityLevel);
1584
- this.youtubePlayer.playVideo();
1591
+ this.youtubePlayer.seekTo(currentTime, true);
1592
+ if (!wasPlaying) {
1593
+ this.youtubePlayer.pauseVideo();
1594
+ }
1585
1595
  }, 100);
1586
- }
1596
+ }, 50);
1597
+
1598
+ this.debugLog('🔄 Applied seekTo trick for quality change');
1587
1599
  } catch (e) {
1588
- this.debugWarn('Force quality change with pause/play failed:', e);
1600
+ this.debugWarn('Force quality change with seekTo trick failed:', e);
1589
1601
  }
1590
1602
  }
1591
1603
 
1592
- // Verify quality was changed after a delay
1593
- setTimeout(() => {
1594
- try {
1595
- const currentQuality = this.youtubePlayer.getPlaybackQuality();
1596
- this.youtubeCurrentQuality = qualityMap[currentQuality] || qualityMap['auto'];
1597
-
1598
- this.debugLog('📊 Current quality after set:', currentQuality, '(', this.youtubeCurrentQuality?.label, ')');
1599
-
1600
- // Show notification with result - be more user-friendly
1601
- if (currentQuality === qualityLevel) {
1604
+ // Verify quality was changed after multiple delays with retry logic
1605
+ this.verifyYouTubeQualityChange(qualityLevel, qualityMap, 0);
1606
+ } catch (error) {
1607
+ this.debugWarn('❌ Could not set YouTube quality:', error);
1608
+ this.showNotification('Quality control limited on YouTube');
1609
+ }
1610
+ }
1611
+
1612
+ /**
1613
+ * Verify YouTube quality change with retry logic
1614
+ */
1615
+ private verifyYouTubeQualityChange(requestedQuality: string, qualityMap: Record<string, any>, attempt: number): void {
1616
+ const maxAttempts = 3;
1617
+ const delays = [500, 1500, 3000]; // Progressive delays
1618
+
1619
+ setTimeout(() => {
1620
+ try {
1621
+ const currentQuality = this.youtubePlayer.getPlaybackQuality();
1622
+ this.youtubeCurrentQuality = qualityMap[currentQuality] || qualityMap['auto'];
1623
+
1624
+ this.debugLog('🔍 Quality verification attempt', attempt + 1, '- Requested:', requestedQuality, '| Current:', currentQuality);
1625
+
1626
+ if (currentQuality === requestedQuality || attempt >= maxAttempts - 1) {
1627
+ // Success or final attempt
1628
+ if (currentQuality === requestedQuality) {
1602
1629
  this.showNotification(`Quality: ${qualityMap[currentQuality]?.label || 'requested quality'}`);
1603
- this.debugLog('✅ Quality successfully changed to:', qualityLevel);
1630
+ this.debugLog('✅ Quality successfully changed to:', requestedQuality);
1604
1631
  } else {
1605
- // Don't show "YouTube optimized" message to users - it's confusing
1632
+ // Try one more aggressive method on final attempt
1633
+ if (attempt === maxAttempts - 1) {
1634
+ this.debugLog('🔥 Final attempt: Trying loadVideoById method');
1635
+ try {
1636
+ const videoData = this.youtubePlayer.getVideoData();
1637
+ const currentTime = this.youtubePlayer.getCurrentTime();
1638
+
1639
+ // Reload video at current time with suggested quality
1640
+ this.youtubePlayer.loadVideoById({
1641
+ videoId: videoData.video_id,
1642
+ startSeconds: currentTime,
1643
+ suggestedQuality: requestedQuality
1644
+ });
1645
+
1646
+ this.debugLog('🔄 Video reloaded with suggested quality:', requestedQuality);
1647
+ } catch (e) {
1648
+ this.debugWarn('loadVideoById method failed:', e);
1649
+ }
1650
+ }
1651
+
1606
1652
  this.showNotification(`Quality: ${qualityMap[currentQuality]?.label || currentQuality}`);
1607
- this.debugLog('⚠️ Requested quality:', qualityLevel, '| Actual quality:', currentQuality, '(YouTube may have optimized)');
1653
+ this.debugLog('⚠️ Quality change may not have worked. Requested:', requestedQuality, '| Current:', currentQuality);
1608
1654
  }
1609
1655
 
1610
- // Update quality badge
1656
+ // Update UI regardless
1611
1657
  this.updateQualityBadge();
1658
+ this.updateSettingsMenu();
1659
+ } else {
1660
+ // Retry with more aggressive method
1661
+ this.debugLog('🔁 Quality not changed, retrying with method', attempt + 2);
1662
+ this.retryYouTubeQualityChange(requestedQuality, qualityMap, attempt + 1);
1612
1663
 
1613
- // Update settings menu UI
1664
+ // Still verify after delay
1665
+ this.verifyYouTubeQualityChange(requestedQuality, qualityMap, attempt + 1);
1666
+ }
1667
+ } catch (verifyError) {
1668
+ this.debugWarn('Could not verify YouTube quality:', verifyError);
1669
+ if (attempt === maxAttempts - 1) {
1670
+ this.showNotification('Quality change attempted');
1671
+ this.updateQualityBadge();
1614
1672
  this.updateSettingsMenu();
1615
- } catch (verifyError) {
1616
- this.debugWarn('Could not verify YouTube quality:', verifyError);
1617
1673
  }
1618
- }, 1000);
1619
-
1620
- } catch (error) {
1621
- this.debugWarn('❌ Could not set YouTube quality:', error);
1622
- this.showNotification('Quality control limited on YouTube');
1674
+ }
1675
+ }, delays[attempt] || 1000);
1676
+ }
1677
+
1678
+ /**
1679
+ * Retry YouTube quality change with alternative methods
1680
+ */
1681
+ private retryYouTubeQualityChange(qualityLevel: string, qualityMap: Record<string, any>, attempt: number): void {
1682
+ try {
1683
+ if (attempt === 1) {
1684
+ // Second attempt: Try with video restart
1685
+ this.debugLog('🔄 Retry attempt 1: Using cueVideoById');
1686
+ const videoData = this.youtubePlayer.getVideoData();
1687
+ const currentTime = this.youtubePlayer.getCurrentTime();
1688
+
1689
+ this.youtubePlayer.cueVideoById({
1690
+ videoId: videoData.video_id,
1691
+ startSeconds: currentTime,
1692
+ suggestedQuality: qualityLevel
1693
+ });
1694
+
1695
+ setTimeout(() => this.youtubePlayer.playVideo(), 100);
1696
+
1697
+ } else if (attempt === 2) {
1698
+ // Third attempt: Multiple sequential calls
1699
+ this.debugLog('🔄 Retry attempt 2: Multiple sequential calls');
1700
+
1701
+ for (let i = 0; i < 3; i++) {
1702
+ setTimeout(() => {
1703
+ this.youtubePlayer.setPlaybackQuality(qualityLevel);
1704
+ }, i * 100);
1705
+ }
1706
+ }
1707
+ } catch (e) {
1708
+ this.debugWarn('Retry attempt', attempt, 'failed:', e);
1623
1709
  }
1624
1710
  }
1625
1711