You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ExoPlayer2.15.0无法解析createWithNotificationChannel符号如何解决?

问题根因

  • 语法错误:createWithNotificationChannel是PlayerNotificationManager的静态工厂方法,无需使用new关键字实例化,代码中多余的new会直接导致语法报错
  • 依赖缺失:ExoPlayer从2.14.0版本开始将PlayerNotificationManager相关组件从核心库拆分到exoplayer-ui独立模块,仅引入核心库无法找到对应类和方法
  • 导包错误:如果导入了旧版本废弃路径的同名类,也会出现方法找不到的报错

修复步骤

  1. 补充依赖,在Module级别的build.gradle文件中添加和你当前核心库版本一致的ui依赖:
implementation 'com.google.android.exoplayer:exoplayer-ui:2.15.0'

添加完成后同步Gradle配置。

  1. 修正代码中的语法错误,删除方法调用前的new关键字,完整修正后的代码如下:
PlayerNotificationManager playerNotificationManager = PlayerNotificationManager.createWithNotificationChannel(
        context, 1, "marakesh",
        8,
        new PlayerNotificationManager.MediaDescriptionAdapter() {
            @Override
            public CharSequence getCurrentContentTitle(Player player) {
                return null;
            }

            @Nullable
            @Override
            public PendingIntent createCurrentContentIntent(Player player) {
                Intent intent = new Intent(context, MainActivity.class);
                return PendingIntent.getActivity(
                        context,
                        0,
                        intent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
            }

            @Nullable
            @Override
            public CharSequence getCurrentContentText(Player player) {
                return null;
            }

            @Nullable
            @Override
            public Bitmap getCurrentLargeIcon(Player player, PlayerNotificationManager.BitmapCallback callback) {
                //return SampleStream.getBitmap(context, bitmapResource);
                return null;
            }
        },
        new PlayerNotificationManager.NotificationListener(){
            @Override
            public void onNotificationPosted(int notificationId, Notification notification, boolean ongoing) {
                startForeground(notificationId, notification);
            }
            @Override
            public void onNotificationCancelled(int notificationId, boolean dissmissedByuser){
                stopSelf();
            }
        });
playerNotificationManager.setPlayer(player);
  1. 确认类导入路径正确,导入的是拆分后的ui包下的类:
import com.google.android.exoplayer2.ui.PlayerNotificationManager;
  1. 清理项目缓存后重新构建即可解决报错。

内容的提问来源于stack exchange,提问作者MarioS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 22:15:03