目录
前言
- 记录使用audioplayers包时出现的问题,测试环境主要是 安卓11
问题
无法读取assets文件
- 这里是希望读取app自带文件 “file/music.mp3” 作为音乐来播放
- 那么首先就需要确保你是否已经在 pubspec.yaml 中加入了这个文件:
- 但仍然报错,报错代码行:audioPlayer.setSource(AssetSource("file/music.mp3"));
E/flutter (32073): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Unable to load asset: assets/file/music.mp3
E/flutter (32073): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:258:7)
E/flutter (32073): <asynchronous suspension>
E/flutter (32073): #1 AudioCache.fetchToMemory (package:audioplayers/src/audio_cache.dart:75:22)
E/flutter (32073): <asynchronous suspension>
E/flutter (32073): #2 AudioCache.load (package:audioplayers/src/audio_cache.dart:101:31)
E/flutter (32073): <asynchronous suspension>
E/flutter (32073): #3 AudioPlayer.setSourceAsset (package:audioplayers/src/audioplayer.dart:237:17)
- 可以看到开头第一句报错,“Unable to load asset: assets/file/music.mp3”,但我们指定的文件是"file/music.mp3",即audioPlayer有一个默认路径前缀"assets/"。
- 解决办法:通过 audioPlayer.audioCache.prefix = ''; 去掉它的默认前缀,然后再调用 audioPlayer.setSource(AssetSource("file/music.mp3")); 读取mp3文件即可。
本地资源/网络资源都无法播放
- 报错信息
......
D/MediaCodecList(32073): codecHandlesFormat: no format, so no extra checks
D/CCodec (32073): allocate(c2.android.mp3.decoder)
I/CCodec (32073): setting up 'default' as default (vendor) store
I/CCodec (32073): Created component [c2.android.mp3.decoder]
D/CCodecConfig(32073): read media type: audio/mpeg
D/ReflectedParamUpdater(32073): extent() != 1 for single value type: algo.buffers.max-count.values
D/ReflectedParamUpdater(32073): extent() != 1 for single value type: output.subscribed-indices.values
D/ReflectedParamUpdater(32073): extent() != 1 for single value type: input.buffers.allocator-ids.values
D/ReflectedParamUpdater(32073): extent() != 1 for single value type: output.buffers.allocator-ids.values
D/ReflectedParamUpdater(32073): extent() != 1 for single value type: algo.buffers.allocator-ids.values
D/ReflectedParamUpdater(32073): extent() != 1 for single value type: output.buffers.pool-ids.values
D/ReflectedParamUpdater(32073): extent() != 1 for single value type: algo.buffers.pool-ids.values
......
D/CCodecBufferChannel(32073): [c2.android.mp3.decoder#231] MediaCodec discarded an unknown buffer
I/hw-BpHwBinder(32073): onLastStrongRef automatically unlinking death recipients
......
- 这个问题可能是因为你使用了lowLatency(低延迟)播放模式,即使用了 audioPlayer.setPlayerMode(PlayerMode.lowLatency);
- audioplayers有两种播放模式PlayerMode:
- mediaPlayer:最常用的播放模式,对时延要求不高的声音输出采用该模式,边加载边播放。
- lowLatency:低延迟播放模式,用于按键音、游戏背景音等对时延要求高场景,一次加载完数据。
- 具体差别我还不了解,但实践中,无论在虚拟机还是真机,一使用lowLatency就无法播放,因此可以试试切换为mediaPlayer使用:
- audioPlayer.setPlayerMode(PlayerMode.mediaPlayer);
网络资源加载失败
- 使用lowLatency播放模式时的报错内容:
- 之所以强调lowLatency,是因为对于同一个问题,mediaPlayer 和 lowLatency 的报错信息是不同的,而且我觉得 lowLatency 的比较清晰。
......
Unexpected error!
D/AudioPlayers(31616): java.io.IOException: Cleartext HTTP traffic to {xxx.域名} not permitted
......
- 那么百度这一句报错后,很多 安卓 原生的文章提到,在高版本的安卓中不允许不加密的明文链接,说人话就是不让你用http链接,需要走https
- 解决办法:
- 方法1:明显的当然就是换https链接了。
- 方法2:
- 修改android/app/src/main/AndriodManifest.xml文件:
- -
- 在application标签的属性中添加:android:usesCleartextTraffic="true"
- 注意是 <application 这里></application> ,而不是 <application>不是这里</application>
- 方法3:同样的修改 AndroidManifest.xml 文件
- 修改/添加 <manifest> 标签的属性 android:targetSandboxVersion="1"
http://pharmworld.store/# online pharmacy non prescription drugs
п»їlegitimate online pharmacies india mail order pharmacy india п»їlegitimate online pharmacies india
super kamagra: cheap kamagra – Kamagra 100mg
Generic Cialis without a doctor prescription cialist.pro Cialis without a doctor prescription
https://viagras.online/# viagra canada
https://cenforce.pro/# cenforce for sale
sildenafil oral jelly 100mg kamagra super kamagra sildenafil oral jelly 100mg kamagra
Tadalafil Tablet Generic Tadalafil 20mg price Buy Tadalafil 20mg
http://cenforce.pro/# order cenforce
https://levitrav.store/# Vardenafil online prescription
cenforce.pro: Cenforce 150 mg online – cenforce.pro
super kamagra: kamagra.win – Kamagra 100mg price
https://cenforce.pro/# order cenforce
Tadalafil price: buy cialis overseas – Buy Tadalafil 10mg
https://viagras.online/# cheapest viagra
buy kamagra online usa kamagra oral jelly super kamagra
super kamagra buy kamagra online buy Kamagra
http://kamagra.win/# Kamagra 100mg price
Kamagra tablets п»їkamagra sildenafil oral jelly 100mg kamagra
Viagra online price: Buy Viagra online cheap – generic sildenafil
http://kamagra.win/# Kamagra Oral Jelly
Cenforce 150 mg online: Cenforce 100mg tablets for sale – cenforce for sale
cenforce.pro: cheapest cenforce – Buy Cenforce 100mg Online
cenforce.pro: cenforce for sale – Purchase Cenforce Online
http://cenforce.pro/# cenforce.pro
cheapest viagra: Cheapest place to buy Viagra – viagra canada
Kamagra 100mg kamagra.win Kamagra tablets
Hello my loved one I want to say that this post is amazing great written and include almost all significant infos I would like to look extra posts like this
http://levitrav.store/# Buy Vardenafil 20mg online
cenforce.pro Buy Cenforce 100mg Online Cenforce 150 mg online
cheap kamagra kamagra.win super kamagra
https://cialist.pro/# п»їcialis generic
viagra canada: Viagra generic over the counter – Generic Viagra for sale
https://levitrav.store/# buy Levitra over the counter
Levitra tablet price: Buy Vardenafil 20mg – Buy Vardenafil 20mg
Generic Cialis price: Cialis 20mg price in USA – Cialis 20mg price
sildenafil oral jelly 100mg kamagra kamagra pills Kamagra tablets
https://kamagra.win/# Kamagra 100mg price
Tadalafil price: Generic Tadalafil 20mg price – Cialis without a doctor prescription
https://levitrav.store/# Cheap Levitra online
https://cenforce.pro/# Cenforce 100mg tablets for sale
buy kamagra online usa kamagra Kamagra 100mg
http://viagras.online/# Cheap generic Viagra online
https://cenforce.pro/# Cenforce 100mg tablets for sale
Cenforce 150 mg online cheapest cenforce Purchase Cenforce Online
Generic Viagra online: Cheapest Sildenafil online – Viagra tablet online
Buy Cenforce 100mg Online: cenforce.pro – Cenforce 100mg tablets for sale
https://viagras.online/# viagra without prescription
Cenforce 150 mg online buy cenforce cheapest cenforce
best price for viagra 100mg: Buy Viagra online – Buy Viagra online cheap