目录
前言
- 记录使用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"
where can i buy erectile dysfunction pills best ed meds online buy erectile dysfunction pills online
http://onlinepharmacyworld.shop/# canadian pharmacy without prescription
https://edpill.top/# buy ed medication
ed pills for sale: order ed pills – buy ed pills
non prescription online pharmacy india: online pharmacy no prescription – canadian pharmacy no prescription needed
canadian pharmacy no prescription canadian pharmacy coupon code cheap pharmacy no prescription
http://onlinepharmacyworld.shop/# online pharmacy discount code
ed medicines: online erectile dysfunction – ed prescription online
http://medicationnoprescription.pro/# canadian pharmacy non prescription
https://edpill.top/# buy ed medication
canadian pharmacies not requiring prescription cheapest pharmacy to fill prescriptions without insurance pharmacy coupons
https://medicationnoprescription.pro/# best website to buy prescription drugs
canadian pharmacy no prescription: canadian pharmacy without prescription – cheapest pharmacy prescription drugs
http://medicationnoprescription.pro/# no prescription canadian pharmacy
buy drugs without prescription canadian prescription how to buy prescriptions from canada safely
https://onlinepharmacyworld.shop/# canadian pharmacy without prescription
best online pharmacy no prescription: mail order prescription drugs from canada – no prescription pharmacy paypal
cheapest ed treatment: ed rx online – ed medications cost
https://edpill.top/# cheap ed
http://medicationnoprescription.pro/# order prescription drugs online without doctor
zithromax 250 mg pill zithromax cost canada zithromax prescription in canada
http://amoxicillina.top/# can i buy amoxicillin over the counter in australia
zithromax 250mg: where can i buy zithromax medicine – zithromax capsules
http://azithromycina.pro/# zithromax 250
buy prednisone 10mg online: buy prednisone nz – buy prednisone 20mg
http://prednisonea.store/# how can i order prednisone
prednisone 5 mg: 1 mg prednisone daily – prednisone 20mg tablets where to buy
amoxil pharmacy can i purchase amoxicillin online generic amoxicillin
stromectol tablet 3 mg: minocycline 50mg tablets online – ivermectin 9 mg
order cheap clomid without dr prescription: how to buy cheap clomid – generic clomid without dr prescription
http://stromectola.top/# stromectol 3 mg tablet
where can i buy zithromax capsules where to get zithromax over the counter zithromax z-pak
10 mg prednisone: prednisone brand name india – prednisone online for sale
https://amoxicillina.top/# price of amoxicillin without insurance
where to get zithromax over the counter: generic zithromax 500mg – zithromax prescription
prednisone 4 mg daily: prednisone 20mg tablets where to buy – buy prednisone mexico
purchase prednisone from india prednisone 50 mg buy prednisone 12 tablets price
https://stromectola.top/# stromectol order online
zithromax generic cost: zithromax pill – buy azithromycin zithromax
where to get cheap clomid price where can i get generic clomid now how to get cheap clomid prices
how can i get generic clomid online: where to buy cheap clomid no prescription – get cheap clomid online
minocycline 50mg without doctor: buy minocycline 100 mg – minocycline 50mg tablets for humans for sale
get cheap clomid no prescription: where to buy cheap clomid tablets – where to get clomid prices
buy cipro online buy cipro online without prescription ciprofloxacin over the counter
order cytotec online: buy cytotec online – Cytotec 200mcg price
doxycycline online: generic doxycycline – where can i get doxycycline
tamoxifen endometrium what happens when you stop taking tamoxifen tamoxifen for men
https://ciprofloxacin.guru/# buy cipro online without prescription
tamoxifen cyp2d6: effexor and tamoxifen – tamoxifen and osteoporosis
diflucan generic price: diflucan rx price – buy diflucan