目录
前言
- 记录使用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"
can you buy prednisone online uk prednisone can you buy prednisone over the counter in usa
cheap amoxicillin 500mg Amoxicillin buy online amoxicillin buy no prescription
amoxicillin cephalexin: amoxicillin cost australia – amoxicillin 500mg tablets price in india
amoxicillin 1000 mg capsule http://clomidrexpharm.com/# how can i get clomid no prescription
Тут можно преобрести оружейные сейфы интернет магазин сейф для хранения оружия
where to buy amoxicillin: amoxil com pharm – amoxicillin order online no prescription
amoxicillin 500 mg tablet price https://prednisoneraypharm.com/# buy prednisone online no prescription
order amoxicillin online: amoxil com pharm – where can i get amoxicillin 500 mg
where can i buy amoxocillin: Com Pharm – amoxicillin for sale
prednisone 10mg tabs: prednisone otc uk – prednisone 0.5 mg
priligy max pharm dapoxetine online priligy max pharm
dapoxetine online priligy max pharm priligy max pharm
amoxicillin generic https://priligymaxpharm.com/# buy dapoxetine online
prednisone canada prescription: cheap prednisone – prednisone buy
medication from mexico pharmacy: mexican drugstore online – mexican drugstore online
mexican rx online mexican pharmacy mexico pharmacies prescription drugs
http://canadiandrugsgate.com/# ed cures that work
male erection: canadiandrugsgate.com – erectial dysfunction
prescription drugs online: Best Canadian pharmacy – canadian pharmacy
cause of ed: canadian pharmacy – ed pills
viagra without a doctor prescription: canadian drugs gate – erection pills
Тут можно преобрести сейф огнестойкий купить огнеупорные сейфы
best online pharmacies in mexico mexican drugstore online mexican mail order pharmacies
https://canadiandrugsgate.com/# what type of medicine is prescribed for allergies
Online medicine order: Indian pharmacy international shipping – online shopping pharmacy india
https://indianpharmacyeasy.com/# Online medicine order
cheap online pharmacy: canadian pharmacy drugs gate – erectile dysfunction medications
pharmacies in mexico that ship to usa: Mexican Pharmacy Gate – purple pharmacy mexico price list
buy drug online: canadiandrugsgate – cheap online pharmacy
http://mexicanpharmgate.com/# mexico drug stores pharmacies
https://indianpharmacyeasy.com/# pharmacy website india
treat ed canadian drugs gate online canadian pharmacy
http://mexicanpharmgate.com/# mexico drug stores pharmacies
https://canadiandrugsgate.com/# herbal ed remedies
medicine in mexico pharmacies: Mexican Pharm Gate – buying from online mexican pharmacy
ed doctors Canadian pharmacy online natural ed
https://mexicanpharmgate.com/# п»їbest mexican online pharmacies
mexican mail order pharmacies: mexican pharmacy – purple pharmacy mexico price list
http://canadiandrugsgate.com/# pet meds without vet prescription canada
indian pharmacy: Indian pharmacy international shipping – cheapest online pharmacy india
online pharmacy india: indian pharmacy – indian pharmacy paypal
http://mexicanpharmgate.com/# buying prescription drugs in mexico
what causes ed: canadian drugs gate – erectile dysfunction medications
http://mexicanpharmgate.com/# buying prescription drugs in mexico online
https://indianpharmacyeasy.com/# best india pharmacy
best india pharmacy Indian pharmacy to USA reputable indian online pharmacy
https://canadiandrugsgate.com/# pain meds without written prescription
how to buy priligy im 16 years old The impact of hormonal deprivation therapy for cancer treatment and the risk of CVD is discussed further below
https://mexicanpharmgate.com/# mexican pharmaceuticals online
buying prescription drugs in mexico MexicanPharmGate mexican pharmaceuticals online