资产音频播放器无法在发布模式下播放歌曲

时间:2021-03-08 15:58:20

标签: flutter

我尝试使用颤振资产音频播放器制作音乐播放器。当我在调试模式下播放歌曲时,它可以正常工作,但是当我构建 APK 时,它不播放歌曲并崩溃。

崩溃日志

<块引用>

C:\Users\Administrator>adb logcat -b crash 03-08 17:19:08.725 30418 30418 E AndroidRuntime:致命异常:主要 03-08 17:19:08.725 30418 30418 E AndroidRuntime:进程:com.example.music,PID:30418 03-08 17:19:08.725 30418 30418 E AndroidRuntime: java.lang.IllegalStateException: 带有主调度程序的模块是 失踪。添加提供主要调度程序的依赖项,例如 'kotlinx-coroutines-android' 并确保它的版本与 'kotlinx-coroutines-core' 03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 f.a.w1.p.a(未知来源:4)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 f.a.w1.q.h(未知来源:55)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 f.a.w1.q.b(未知来源:0)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 f.a.w1.e.a(来源不明:16)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 f.a.x1.a.a(未知来源:15)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 f.a.x1.a.a(未知来源:5)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 f.a.d0.a(未知来源:41)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 f.a.a.a(未知 来源:3) 03-08 17:19:08.725 30418 30418 E AndroidRuntime: at f.a.d.a(未知来源:22)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 f.a.c.a(未知来源:0)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 f.a.d.a(未知来源:12) 03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 f.a.c.a(未知来源:0)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 c.a.a.a.g.a(未知来源:139)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 c.a.a.a.b.a(未知来源:706)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 d.a.c.a.i$a.a(未知来源:17)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 io.flutter.embedding.engine.e.b.a(未知来源:57)03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(未知) 来源:4) 03-08 17:19:08.725 30418 30418 E AndroidRuntime: at android.os.MessageQueue.nativePollOnce(原生方法) 03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 android.os.MessageQueue.next(MessageQueue.java:336) 03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 android.os.Looper.loop(Looper.java:174) 03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 android.app.ActivityThread.main(ActivityThread.java:7356) 03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 java.lang.reflect.Method.invoke(Native Method) 03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491) 03-08 17:19:08.725 30418 30418 E AndroidRuntime:在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:940)

onTap 功能

onTap: () {
        if (model.player.playerState.value == PlayerState.stop) {
          model.play(index);
        } else if (model.player.current.value.audio.audio !=
            model.allSongs[index]) {
          model.play(index);
        }
      },

播放功能

play(index) {
    player.stop();
    player.open(
        Playlist(
          audios: allSongs,
          startIndex: index ?? 0,
        ),
        loopMode: player.currentLoopMode,
        showNotification: true,
        notificationSettings: NotificationSettings(
            stopEnabled: false,
            seekBarEnabled: false,
            customPlayPauseAction: pause()));

    notifyListeners();
  }

android 文件夹中的build.gradle

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app 文件夹中的 build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.music"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

1 个答案:

答案 0 :(得分:0)

您的错误日志说:

<块引用>

缺少带有主调度程序的模块。添加提供 Main 的依赖项 调度员,例如'kotlinx-coroutines-android' 并确保它具有 与 'kotlinx-coroutines-core' 版本相同

您是否尝试添加这些库? https://github.com/Kotlin/kotlinx.coroutines