mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 07:13:00 +00:00 
			
		
		
		
	Added a restart song button to signle track expanded notification
... and some comments to the code
This commit is contained in:
		| @@ -219,20 +219,30 @@ public final class BackgroundPlayer extends Service { | |||||||
|         remoteViews.setOnClickPendingIntent(R.id.notificationContent, |         remoteViews.setOnClickPendingIntent(R.id.notificationContent, | ||||||
|                 PendingIntent.getActivity(this, NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT)); |                 PendingIntent.getActivity(this, NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT)); | ||||||
|  |  | ||||||
|         if (basePlayerImpl.playQueue != null && basePlayerImpl.playQueue.size() > 1) { |         // Lets check if we are playing more than one song in the background | ||||||
|  |         if (basePlayerImpl.playQueue != null && basePlayerImpl.playQueue.size() > 1) { // If we have more than one song | ||||||
|  |             // Use track skiping for forward and back | ||||||
|             remoteViews.setInt(R.id.notificationFRewind, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_previous); |             remoteViews.setInt(R.id.notificationFRewind, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_previous); | ||||||
|             remoteViews.setInt(R.id.notificationFForward, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_next); |             remoteViews.setInt(R.id.notificationFForward, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_next); | ||||||
|             remoteViews.setOnClickPendingIntent(R.id.notificationFRewind, |             remoteViews.setOnClickPendingIntent(R.id.notificationFRewind, | ||||||
|                     PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT)); |                     PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT)); | ||||||
|             remoteViews.setOnClickPendingIntent(R.id.notificationFForward, |             remoteViews.setOnClickPendingIntent(R.id.notificationFForward, | ||||||
|                     PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT)); |                     PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT)); | ||||||
|         } else { |             // We dont need a restart track button (skip track backwards) | ||||||
|  |             remoteViews.setViewVisibility(R.id.notificationRestartTrack, View.INVISIBLE); | ||||||
|  |         } else { // But if we only have one song | ||||||
|  |             // Use time skipping for fastforward/rewind | ||||||
|             remoteViews.setInt(R.id.notificationFRewind, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_rewind); |             remoteViews.setInt(R.id.notificationFRewind, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_rewind); | ||||||
|             remoteViews.setInt(R.id.notificationFForward, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_fastforward); |             remoteViews.setInt(R.id.notificationFForward, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_fastforward); | ||||||
|             remoteViews.setOnClickPendingIntent(R.id.notificationFRewind, |             remoteViews.setOnClickPendingIntent(R.id.notificationFRewind, | ||||||
|                     PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_FAST_REWIND), PendingIntent.FLAG_UPDATE_CURRENT)); |                     PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_FAST_REWIND), PendingIntent.FLAG_UPDATE_CURRENT)); | ||||||
|             remoteViews.setOnClickPendingIntent(R.id.notificationFForward, |             remoteViews.setOnClickPendingIntent(R.id.notificationFForward, | ||||||
|                     PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_FAST_FORWARD), PendingIntent.FLAG_UPDATE_CURRENT)); |                     PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_FAST_FORWARD), PendingIntent.FLAG_UPDATE_CURRENT)); | ||||||
|  |             // Add a restart track button (skip track backwards) | ||||||
|  |             remoteViews.setViewVisibility(R.id.notificationRestartTrack, View.VISIBLE); | ||||||
|  |             remoteViews.setOnClickPendingIntent(R.id.notificationRestartTrack, | ||||||
|  |                     PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT)); | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         setRepeatModeIcon(remoteViews, basePlayerImpl.getRepeatMode()); |         setRepeatModeIcon(remoteViews, basePlayerImpl.getRepeatMode()); | ||||||
|   | |||||||
| @@ -116,6 +116,22 @@ | |||||||
|             android:src="@drawable/ic_repeat_white" |             android:src="@drawable/ic_repeat_white" | ||||||
|             tools:ignore="ContentDescription"/> |             tools:ignore="ContentDescription"/> | ||||||
|  |  | ||||||
|  |         <ImageButton | ||||||
|  |             android:id="@+id/notificationRestartTrack" | ||||||
|  |             android:layout_width="40dp" | ||||||
|  |             android:layout_height="match_parent" | ||||||
|  |             android:layout_centerVertical="true" | ||||||
|  |             android:layout_marginRight="5dp" | ||||||
|  |             android:layout_toLeftOf="@+id/notificationFRewind" | ||||||
|  |             android:background="#00000000" | ||||||
|  |             android:clickable="true" | ||||||
|  |             android:focusable="true" | ||||||
|  |             android:padding="2dp" | ||||||
|  |             android:scaleType="fitCenter" | ||||||
|  |             android:src="@drawable/exo_controls_previous" | ||||||
|  |             android:visibility="gone" | ||||||
|  |             tools:ignore="ContentDescription"/> | ||||||
|  |  | ||||||
|         <ImageButton |         <ImageButton | ||||||
|             android:id="@+id/notificationFRewind" |             android:id="@+id/notificationFRewind" | ||||||
|             android:layout_width="40dp" |             android:layout_width="40dp" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Peter Hindes
					Peter Hindes