exoplayer 通知管理器不显示搜索栏拇指

Posted

技术标签:

【中文标题】exoplayer 通知管理器不显示搜索栏拇指【英文标题】:exoplayer notification manager doesn't show seekbar thumb 【发布时间】:2022-01-24 07:47:03 【问题描述】:

我正在使用 exo 播放器通知管理器来显示我的歌曲媒体播放通知,但不幸的是 seekbar 拇指、当前位置和最大持续时间没有显示,我现在得到的只是那个进度条。

enter image description here

这是我用来启动通知的前台服务

public class audioPlayerService extends Service 
private SimpleExoPlayer player;
private PlayerNotificationManager playerNotificationManager;
private MediaSessionCompat mediaSession;
private CacheDataSource.Factory factory;
private DefaultDataSourceFactory dataSourceFactory;
private Bitmap icon;

@Override
public void onCreate() 
    super.onCreate();

    final Context context = this;

    player = new SimpleExoPlayer.Builder(context).build();

    dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, context.getResources().getString(R.string.app_name)));
    factory = new CacheDataSource.Factory().setCache(downloadUtil.getCache(context))
            .setUpstreamDataSourceFactory(dataSourceFactory);

    playerNotificationManager = new PlayerNotificationManager.Builder(context, 151,
            context.getResources().getString(R.string.app_name))
            .setChannelNameResourceId(R.string.app_name)
            .setChannelImportance(IMPORTANCE_HIGH)
            .setMediaDescriptionAdapter(new PlayerNotificationManager.MediaDescriptionAdapter() 
                @Override
                public CharSequence getCurrentContentTitle(Player player) 
                    return player.getCurrentMediaItem().mediaMetadata.displayTitle;
                

                @Nullable
                @Override
                public PendingIntent createCurrentContentIntent(Player player) 
                    return null;
                

                @Nullable
                @Override
                public CharSequence getCurrentContentText(Player player) 
                    return player.getCurrentMediaItem().mediaMetadata.artist;
                

                @Nullable
                @Override
                public Bitmap getCurrentLargeIcon(Player player, PlayerNotificationManager.BitmapCallback callback) 
                    if (icon == null) 
                        icon = BitmapFactory.decodeResource(context.getResources(),
                                R.drawable.logo);
                    
                    Glide.with(context)
                            .asBitmap()
                            .load(player.getCurrentMediaItem().mediaMetadata.artworkUri)
                            .into(new CustomTarget<Bitmap>() 
                                @Override
                                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) 
                                    icon=resource;
                                    callback.onBitmap(resource);
                                

                                @Override
                                public void onLoadCleared(@Nullable Drawable placeholder) 

                                
                            );
                    return icon;
                

            ).setNotificationListener(new PlayerNotificationManager.NotificationListener() 
                @Override
                public void onNotificationCancelled(int notificationId, boolean dismissedByUser) 
                    stopSelf();
                

                @Override
                public void onNotificationPosted(int notificationId, Notification notification, boolean ongoing) 
                    if (ongoing) 
                        // Here Audio is playing, so we need to make sure the service will not get destroyed by calling startForeground.
                        startForeground(notificationId, notification);
                     else 
                        //Here audio has stopped playing, so we can make notification dismissible on swipe.
                        stopForeground(false);
                    
                
            )
            .build();

    playerNotificationManager.setPlayer(player);
    playerNotificationManager.setSmallIcon(R.drawable.logo);
    playerNotificationManager.setUseNextAction(false);
    playerNotificationManager.setUsePreviousAction(false);
    playerNotificationManager.setUseNextActionInCompactView(false);
    playerNotificationManager.setUsePreviousActionInCompactView(false);
    playerNotificationManager.setUseChronometer(true);


    mediaSession = new MediaSessionCompat(context, context.getResources().getString(R.string.app_name));
    mediaSession.setActive(true);

    MediaSessionConnector mediaSessionConnector =
            new MediaSessionConnector(mediaSession);
    mediaSessionConnector.setPlayer(player);
    playerNotificationManager.setMediaSessionToken(mediaSession.getSessionToken());



@Override
public void onDestroy() 
    playerNotificationManager.setPlayer(player);
    player.release();
    player = null;
    super.onDestroy();


@Nullable
@Override
public IBinder onBind(Intent intent) 
    return null;


@Override
public int onStartCommand(Intent intent, int flags, int startId) 
    BookElement book = intent.getParcelableExtra("track");

    mediaSession.setMetadata(new MediaMetadataCompat.Builder().putLong(MediaMetadataCompat.METADATA_KEY_DURATION,
            (long) (book.getSoundFile().getDuration() * 1000)).build());

    MediaItem mediaItem = new MediaItem.Builder()
            .setUri(Uri.parse(book.getSoundFile().getLocation()))
            .setMediaMetadata(new MediaMetadata.Builder()
                    .setArtworkUri(Uri.parse(book.getThumbnail().getLocation()))
                    .setArtist(book.getAuthor().getName())
                    .setMediaUri(Uri.parse(book.getSoundFile().getLocation()))
                    .setDisplayTitle(book.getTitle())
                    .build())
            .build();
    MediaSource source = new ProgressiveMediaSource.Factory(factory).createMediaSource(mediaItem);

    player.prepare(source);
    player.setPlayWhenReady(true);

    return START_STICKY;

还有我的缓存类

public class downloadUtil 
private static Cache cache;
private static DownloadManager downloadManager;

public static synchronized Cache getCache(Context context)
    if (cache==null)
        File cacheDirectory=new File(context.getExternalFilesDir(null),"downloads");
        cache=new SimpleCache(cacheDirectory,new NoOpCacheEvictor());
    
    return cache;


public static synchronized DownloadManager getDownloadManager(Context context)
    if (downloadManager==null)
        Executor downloadExecutor = Runnable::run;

        downloadManager =
                new DownloadManager(context,new StandaloneDatabaseProvider(context),getCache(context),
                        new DefaultHttpDataSource.Factory(),downloadExecutor);
        downloadManager.setMaxParallelDownloads(3);
    
    return downloadManager;

【问题讨论】:

【参考方案1】:

只在通知中使用单色小图标,或者根本不使用小图标锻炼漂亮

【讨论】:

正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center。 谢谢你,它工作得很好

以上是关于exoplayer 通知管理器不显示搜索栏拇指的主要内容,如果未能解决你的问题,请参考以下文章

Exoplayer 搜索栏预览

一个拇指自定义rangeseekbar android

更改搜索栏拇指的大小

Android中搜索栏的自定义拇指

删除拇指并为禁用的搜索栏设置progressTint

使用搜索栏进度制作拇指的中心文本视图并移动文本视图