gpt4 book ai didi

android - 在android中流式传输音频.pls

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:55:36 27 4
gpt4 key购买 nike

我正在制作一个使用流式传输的类似 radio 的应用程序。在这里,我需要从链接 (http://somedomain/some.pls) 流式传输音频。

我已经创建了 MediaPlayer 并且知道如何播放音频文件。但不知道如何从网上流式传输。

编辑: 我使用以下代码时得到的 logcat

MediaPlayer mp = new MediaPlayer();  
mp.setDataSource(http://somedomain/some.pls);
mp.prepare();
mp.start()

通过日志标签**MediaPlayer**

  02-15 05:50:11.761: VERBOSE/MediaPlayer(23715): constructor
02-15 05:50:11.761: VERBOSE/MediaPlayer(23715): setListener
02-15 05:50:11.761: INFO/MediaPlayer(23715): uri is:http://some:444/sdfd.pls
02-15 05:50:11.761: INFO/MediaPlayer(23715): path is null
02-15 05:50:11.761: DEBUG/MediaPlayer(23715): Couldn't open file on client side, trying server side
02-15 05:50:11.765: VERBOSE/MediaPlayer(23715): setDataSource(http://some:444/sdfd.pls)
02-15 05:50:11.777: VERBOSE/MediaPlayer(23715): prepare
02-15 05:50:13.105: ERROR/MediaPlayer(23715): message received msg=3, ext1=0, ext2=0
02-15 05:50:13.105: VERBOSE/MediaPlayer(23715): buffering 0
02-15 05:50:13.105: ERROR/MediaPlayer(23715): callback application
02-15 05:50:13.105: ERROR/MediaPlayer(23715): back from callback

通过日志标签**PlayerDriver**

02-15 05:50:11.765: VERBOSE/PlayerDriver(2393): constructor
02-15 05:50:11.765: VERBOSE/PlayerDriver(2393): OpenCore hardware module not found
02-15 05:50:11.765: VERBOSE/PlayerDriver(2393): start player thread
02-15 05:50:11.765: VERBOSE/PlayerDriver(2393): startPlayerThread
02-15 05:50:11.769: VERBOSE/PlayerDriver(2393): InitializeForThread
02-15 05:50:11.769: VERBOSE/PlayerDriver(2393): OMX_MasterInit
02-15 05:50:11.769: VERBOSE/PlayerDriver(2393): OsclScheduler::Init
02-15 05:50:11.769: VERBOSE/PlayerDriver(2393): CreatePlayer
02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): AddToScheduler
02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): PendForExec
02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): OsclActiveScheduler::Current
02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): StartScheduler
02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): Send player code: 2
02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): CommandCompleted
02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): Completed command PLAYER_SETUP status=1
02-15 05:50:11.777: INFO/PlayerDriver(2393): PlayerDriver::isProtectedFile(http://some:444/sdfd.pls)
02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): File EXT is : .pls
02-15 05:50:11.777: ERROR/PlayerDriver(2393): PlayerDriver::it is a not Protected file
02-15 05:50:11.781: VERBOSE/PlayerDriver(2393): Send player code: 3
02-15 05:50:11.781: VERBOSE/PlayerDriver(2393): handleSetDataSource
02-15 05:50:11.781: VERBOSE/PlayerDriver(2393): handleSetDataSource- scanning for extension
02-15 05:50:11.800: VERBOSE/PlayerDriver(2393): CommandCompleted
02-15 05:50:11.800: VERBOSE/PlayerDriver(2393): Completed command PLAYER_SET_DATA_SOURCE status=1
02-15 05:50:11.800: VERBOSE/PlayerDriver(2393): Send player code: 6
02-15 05:50:11.800: VERBOSE/PlayerDriver(2393): release string is 2.2 len 3
02-15 05:50:13.101: VERBOSE/PlayerDriver(2393): HandleInformationalEvent: 34
02-15 05:50:13.101: VERBOSE/PlayerDriver(2393): HandleInformationalEvent: 19
02-15 05:50:13.124: VERBOSE/PlayerDriver(2393): HandleInformationalEvent: 20
02-15 05:50:14.511: VERBOSE/PlayerDriver(2393): HandleInformationalEvent: 20
02-15 05:50:16.509: VERBOSE/PlayerDriver(2393): HandleInformationalEvent: 20

这个 02-15 05:50:16.509: VERBOSE/PlayerDriver(2393): HandleInformationalEvent: 20 循环但没有声音..
可能有什么问题..
谢谢。

最佳答案


您可以使用 MediaPlayer 类上提供的文件流功能来执行上述操作。
我没有测试下面的代码,但它应该是这些行:

MediaPlayer mp = new MediaPlayer();  
mp.setDataSource(http://somedomain/some.pls);
mp.prepare();
mp.start();

但请记住执行以下操作:
1. 用 trycatch 语句包围上面的每个语句,并大量打印到 LogCat。这将有助于轻松调试。
2. 完成后释放资源。

HTH,
斯里拉姆

关于android - 在android中流式传输音频.pls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4944321/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com