从JavaScript中播放WebView中的声音

从JavaScript中播放WebView中的声音,第1张

概述我正在尝试从资源中加载到WebView的JavaScript代码中播放声音:WebViewweb_view=(WebView)findViewById(R.id.web_view);web_view.getSettings().setJavaScriptEnabled(true);web_view.setWebChromeClient(newWebChromeClient());web_view.loadUrl("file:///assets/www/ind

我正在尝试从资源中加载到WebVIEw的JavaScript代码中播放声音:

WebVIEw web_vIEw = (WebVIEw) findVIEwByID(R.ID.web_vIEw);web_vIEw.getSettings().setJavaScriptEnabled(true);web_vIEw.setWebChromeClIEnt(new WebChromeClIEnt());web_vIEw.loadUrl("file:///assets/www/index.HTML");

我尝试了以下方法的所有组合,如何使用OGG,MP3和WAV文件播放音频,JavaSrcipt代码位于assets / www / Js / play.Js:

audio = new Audio("../audio/sound.mp3");audio.load();audio.play();audio = new Audio("./audio/sound.mp3");audio.load();audio.play();audio = new Audio("audio/sound.mp3");audio.load();audio.play();audio = new Audio("file:///androID_asset/www/audio/sound.mp3");audio.load();audio.play();audio = new Audio();audio.src = document.getElementByID("audio_tag").src;audio.load();audio.play();

其中audio_tag是< audio ID =“audio_tag”src =“audio / sound.mp3”preload =“auto”>< / audio>,也尝试了路径和格式的所有组合.

但是声音没有播放,只知道可能出现的错误是遵循一般错误:

E/MediaPlayer(1530): error (1, -2147483648)

从这条信息消息中猜测,音频文件的路径应该适用于第二个第五个案例:

I/StagefrightPlayer(33): setDataSource('file:///androID_asset/www/audio/sound.mp3');

虽然这个问题可能被认为是重复的
Android WebView playing audio with javascript并且答案无论如何都没有帮助因为永远不会调用shouldOverrIDeUrlLoading,我试图在这里更精确地指定这个问题.

你有什么可能是错的线索或如何找出它是什么?

谢谢.

编辑:使用AndroID 2.3在galaxy Gio中测试给出了不同的错误集:

02-06 17:15:13.829: V/PlayerDriver(95): AddToScheduler 02-06
17:15:13.829: V/PlayerDriver(95): PendForExec 02-06 17:15:13.829:
V/PlayerDriver(95): OsclActiveScheduler::Current 02-06
17:15:13.829: V/PlayerDriver(95): StartScheduler 02-06
17:15:13.829: V/PVPlayer(95): send PLAYER_SETUP 02-06 17:15:13.829:
V/PlayerDriver(95): Send player code: 2 02-06 17:15:13.829:
V/PlayerDriver(95): CommandCompleted 02-06 17:15:13.829:
V/PlayerDriver(95): Completed command PLAYER_SETUP status=PVMFSuccess
02-06 17:15:13.829: V/PVPlayer(95):
setDataSource(file:///androID_asset/www/audio/sound.mp3) 02-06
17:15:13.839: V/PVPlayer(95): prepareAsync 02-06 17:15:13.839:
V/PVPlayer(95): data source =
file:///androID_asset/www/audio/sound.mp3 02-06 17:15:13.849:
V/PlayerDriver(95): Send player code: 3 02-06 17:15:13.849:
V/PlayerDriver(95): handleSetDataSource 02-06 17:15:13.849:
V/PlayerDriver(95): handleSetDataSource- scanning for extension
02-06 17:15:13.849: V/PlayerDriver(95): HandleinformationalEvent:
PVMFInfoErrorHandlingStart 02-06 17:15:13.849: V/PlayerDriver(95):
HandleinformationalEvent: type=26 UNHANDLED 02-06 17:15:13.849:
W/MediaPlayer(4361): info/warning (1, 26) 02-06 17:15:13.849:
V/PlayerDriver(95): CommandCompleted 02-06 17:15:13.849:
V/PlayerDriver(95): Completed command PLAYER_SET_DATA_SOURCE
status=PVMFErrNotSupported 02-06 17:15:13.849: E/PlayerDriver(95):
Command PLAYER_SET_DATA_SOURCE completed with an error or info
PVMFErrNotSupported 02-06 17:15:13.849: E/MediaPlayer(4361): error
(1, -4) 02-06 17:15:13.849: V/PVPlayer(95): run_init s=-2147483648,
cancelled=0 02-06 17:15:13.849: V/PlayerDriver(95):
HandleinformationalEvent: PVMFInfoErrorHandlingComplete 02-06
17:15:13.849: W/PlayerDriver(95): PVMFInfoErrorHandlingComplete
02-06 17:15:13.939: I/MediaPlayer(4361): Info (1,26) 02-06
17:15:13.939: E/MediaPlayer(4361): Error (1,-4) 02-06 17:15:13.939:
V/PVPlayer(95): reset 02-06 17:15:13.939: V/PlayerDriver(95): Send
player code: 18 02-06 17:15:13.939: V/PlayerDriver(95):
handleCancelAllCommands 02-06 17:15:13.939: V/PlayerDriver(95):
CommandCompleted 02-06 17:15:13.939: V/PlayerDriver(95): Completed
command PLAYER_CANCEL_ALL_COMMANDS status=PVMFSuccess 02-06
17:15:13.939: V/PlayerDriver(95): Send player code: 11 02-06
17:15:13.939: V/PlayerDriver(95): handlereset 02-06 17:15:13.939:
V/PlayerDriver(95): CommandCompleted 02-06 17:15:13.939:
V/PlayerDriver(95): Completed command PLAYER_reset status=PVMFSuccess
02-06 17:15:13.939: V/PlayerDriver(95): Send player code: 17 02-06
17:15:13.939: V/PlayerDriver(95): handleRemoveDataSource 02-06
17:15:13.939: V/PlayerDriver(95): CommandCompleted 02-06
17:15:13.939: V/PlayerDriver(95): Completed command
PLAYER_REMOVE_DATA_SOURCE status=PVMFSuccess 02-06 17:15:13.939:
V/PlayerDriver(95): remove datasource complete 02-06 17:15:13.939:
V/PVPlayer(95): unmap file

解决方法:

我有同样的问题,最后我使用phonegap和cordova,你可以轻松地播放和录制音频:
http://docs.phonegap.com/en/2.9.0/cordova_media_media.md.html

总结

以上是内存溢出为你收集整理的从JavaScript中播放WebView中的声音全部内容,希望文章能够帮你解决从JavaScript中播放WebView中的声音所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1100855.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存