如何在java中从tcp流播放声音 [英] How to play sound from tcp stream in java

查看:29
本文介绍了如何在java中从tcp流播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还有另一个应用程序可以在此套接字上写入原始 wav 文件.客户端启动并开始收听当前正在播放的歌曲.

Socket clientSocket = new Socket("localhost", 9595);AudioInputStream stream = AudioSystem.getAudioInputStream(clientSocket.getInputStream());

<块引用>

我得到javax.sound.sampled.UnsupportedAudioFileException:无法从输入流获取音频输入流

关于 AudioSystem.getAudioInputStream 的文档:从提供的输入流中获取音频输入流.该流必须指向有效的音频文件数据."

如何从 TCP 流播放声音?考虑到客户端无法从音乐开始听.

解决方案

打开 AudioInputStream 不会播放来自此流的声音.您需要打开一个 Clip 来播放来自流的声音.我根本不是专家,但您应该通过阅读 来学习如何做到这一点Java 教程.

There is another app that writes raw wav file on this socket. The client starts and begins listening to the song which is currently playing.

Socket clientSocket = new Socket("localhost", 9595);
AudioInputStream stream = AudioSystem.getAudioInputStream(clientSocket.getInputStream());

I get javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream

Doc about AudioSystem.getAudioInputStream: "Obtains an audio input stream from the provided input stream. The stream must point to valid audio file data."

How to play sound from a TCP stream? Considering the client could not start listening from beginnig of the music.

解决方案

Opening an AudioInputStream doesn't play the sound coming from this stream. You need to open a Clip to play the sound coming from the stream. I'm not an expert at all, but you should learn how to do it by reading the Java tutorial.

这篇关于如何在java中从tcp流播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆