Streaming audio/radio in Java?

那年仲夏 提交于 2019-12-07 15:11:40

问题


I've been looking around the entire web, and tried a bunch of different stuff, but I can't figure out how to play streaming audio in java - which is crucial for the application Iam developing now. It's a radio. I've already written it for the web, but I want a desktop version, and I though java might be the way to go.

Streams look like this (mostly MP3s): http://lyd.nrk.no/nrk_radio_mp3_mp3_h (example from NRK MP3 - a radio channel in Norway).

So where should I go from here? I've tried both JMF, FMJ and a lot of other stuff. I just want to stream audio.. I appreciate all answers, please help me out!


回答1:


Have you tried Java FX 2 (latest version is 2.1)? It has a media component that's rather easy to use. Works well for video including streaming video (even h.264 in JavaFX 2.1) in my experience. Can play normal mp3 files with it, never tried streaming mp3 though.




回答2:


JavaFX 2 does not support mp3 streams, but you can hack it.

Open a socket connection to any ICY mp3 stream in a new thread and start saving the bytes to a file.

After a few kilobytes received open the file in the JavaFX MediaPlayer and play it, but do not stop receiving bytes on the another thread.

This is what worked for me.



来源:https://stackoverflow.com/questions/10438351/streaming-audio-radio-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!