mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 15:23:00 +00:00 
			
		
		
		
	-Fixed audio focus not working with timeline changes.
-Changed circular loading to boundary loading.
This commit is contained in:
		 John Zhen M
					John Zhen M
				
			
				
					committed by
					
						 John Zhen Mo
						John Zhen Mo
					
				
			
			
				
	
			
			
			 John Zhen Mo
						John Zhen Mo
					
				
			
						parent
						
							a0ba3ce2e4
						
					
				
				
					commit
					9576d5bd89
				
			| @@ -440,12 +440,16 @@ public abstract class BasePlayer implements Player.EventListener, | |||||||
|         if (simpleExoPlayer != null) simpleExoPlayer.setVolume(DUCK_AUDIO_TO); |         if (simpleExoPlayer != null) simpleExoPlayer.setVolume(DUCK_AUDIO_TO); | ||||||
|         animateAudio(DUCK_AUDIO_TO, 1f, DUCK_DURATION); |         animateAudio(DUCK_AUDIO_TO, 1f, DUCK_DURATION); | ||||||
|  |  | ||||||
|         if (isResumeAfterAudioFocusGain()) simpleExoPlayer.setPlayWhenReady(true); |         if (isResumeAfterAudioFocusGain()) { | ||||||
|  |             simpleExoPlayer.setPlayWhenReady(true); | ||||||
|  |             wasPlaying = true; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     protected void onAudioFocusLoss() { |     protected void onAudioFocusLoss() { | ||||||
|         if (DEBUG) Log.d(TAG, "onAudioFocusLoss() called"); |         if (DEBUG) Log.d(TAG, "onAudioFocusLoss() called"); | ||||||
|         simpleExoPlayer.setPlayWhenReady(false); |         simpleExoPlayer.setPlayWhenReady(false); | ||||||
|  |         wasPlaying = false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     protected void onAudioFocusLossCanDuck() { |     protected void onAudioFocusLossCanDuck() { | ||||||
| @@ -758,6 +762,7 @@ public abstract class BasePlayer implements Player.EventListener, | |||||||
|             else playQueue.setIndex(0); |             else playQueue.setIndex(0); | ||||||
|         } |         } | ||||||
|         simpleExoPlayer.setPlayWhenReady(!isPlaying()); |         simpleExoPlayer.setPlayWhenReady(!isPlaying()); | ||||||
|  |         wasPlaying = simpleExoPlayer.getPlayWhenReady(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void onFastRewind() { |     public void onFastRewind() { | ||||||
| @@ -774,10 +779,12 @@ public abstract class BasePlayer implements Player.EventListener, | |||||||
|         if (simpleExoPlayer == null || playQueue == null || currentInfo == null) return; |         if (simpleExoPlayer == null || playQueue == null || currentInfo == null) return; | ||||||
|         if (DEBUG) Log.d(TAG, "onPlayPrevious() called"); |         if (DEBUG) Log.d(TAG, "onPlayPrevious() called"); | ||||||
|  |  | ||||||
|         if (simpleExoPlayer.getCurrentPosition() <= PLAY_PREV_ACTIVATION_LIMIT) { |         /* If current playback has run for PLAY_PREV_ACTIVATION_LIMIT milliseconds, restart current track. | ||||||
|             playQueue.offsetIndex(-1); |         * Also restart the track if the current track is the first in a queue.*/ | ||||||
|         } else { |         if (simpleExoPlayer.getCurrentPosition() > PLAY_PREV_ACTIVATION_LIMIT || playQueue.getIndex() == 0) { | ||||||
|             simpleExoPlayer.seekTo(currentInfo.start_position); |             simpleExoPlayer.seekTo(currentInfo.start_position); | ||||||
|  |         } else { | ||||||
|  |             playQueue.offsetIndex(-1); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -211,18 +211,18 @@ public class PlaybackManager { | |||||||
|         // The current item has higher priority |         // The current item has higher priority | ||||||
|         final int currentIndex = playQueue.getIndex(); |         final int currentIndex = playQueue.getIndex(); | ||||||
|         final PlayQueueItem currentItem = playQueue.get(currentIndex); |         final PlayQueueItem currentItem = playQueue.get(currentIndex); | ||||||
|         if (currentItem != null) load(currentItem); |         if (currentItem == null) return; | ||||||
|         else return; |         load(currentItem); | ||||||
|  |  | ||||||
|  |         // Load boundaries to ensure correct looping | ||||||
|  |         if (sourceToQueueIndex.indexOf(0) == -1) load(playQueue.get(0)); | ||||||
|  |         if (sourceToQueueIndex.indexOf(playQueue.size() - 1) == -1) load(playQueue.get(playQueue.size() - 1)); | ||||||
|  |  | ||||||
|         // The rest are just for seamless playback |         // The rest are just for seamless playback | ||||||
|         final int leftBound = Math.max(0, currentIndex - WINDOW_SIZE); |         final int leftBound = Math.max(0, currentIndex - WINDOW_SIZE); | ||||||
|         final int rightLimit = currentIndex + WINDOW_SIZE + 1; |         final int rightBound = Math.min(playQueue.size(), currentIndex + WINDOW_SIZE + 1); | ||||||
|         final int rightBound = Math.min(playQueue.size(), rightLimit); |  | ||||||
|         final List<PlayQueueItem> items = new ArrayList<>(playQueue.getStreams().subList(leftBound, rightBound)); |         final List<PlayQueueItem> items = new ArrayList<>(playQueue.getStreams().subList(leftBound, rightBound)); | ||||||
|  |  | ||||||
|         final int excess = rightLimit - playQueue.size(); |  | ||||||
|         if (excess >= 0) items.addAll(playQueue.getStreams().subList(0, excess)); |  | ||||||
|  |  | ||||||
|         for (final PlayQueueItem item: items) load(item); |         for (final PlayQueueItem item: items) load(item); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -245,7 +245,7 @@ public class PlaybackManager { | |||||||
|                 final MediaSource source = playbackListener.sourceOf(streamInfo, item.getSortedQualityIndex()); |                 final MediaSource source = playbackListener.sourceOf(streamInfo, item.getSortedQualityIndex()); | ||||||
|                 final int itemIndex = playQueue.indexOf(item); |                 final int itemIndex = playQueue.indexOf(item); | ||||||
|                 // replace all except the currently playing |                 // replace all except the currently playing | ||||||
|                 insert(itemIndex, source, false); |                 insert(itemIndex, source, itemIndex != playQueue.getIndex()); | ||||||
|                 if (tryUnblock()) sync(); |                 if (tryUnblock()) sync(); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user