我正在尝试通过VLC Winamp或WMP打开的http上的音频。我目前的代码可以通过RTP协议而不是HTTP来执行此操作。仅将以下代码中的URL更改为HTTP不起作用。如何修改以下代码以通过HTTP进行流?
public class MediaTransmitter {
private MediaLocator mediaLocator = null;
private DataSink dataSink = null;
private Processor mediaProcessor = null;
private static final Format[] FORMATS = new Format[]{new AudioFormat(AudioFormat.MPEG_RTP)};
private static final ContentDescriptor CONTENT_DESCRIPTOR = new ContentDescriptor(ContentDescriptor.RAW_RTP);
public MediaTransmitter(MediaLocator locator) {
mediaLocator = locator;
}
public void startTransmitting() throws IOException {
mediaProcessor.start();
dataSink.open();
dataSink.start();
}
public void stopTransmitting() throws IOException {
dataSink.stop();
dataSink.close();
mediaProcessor.stop();
mediaProcessor.close();
}
public void setDataSource(DataSource ds) throws IOException, NoProcessorException, CannotRealizeException, NoDataSinkException {
mediaProcessor = Manager.createRealizedProcessor(new ProcessorModel(ds, FORMATS, CONTENT_DESCRIPTOR));
dataSink = Manager.createDataSink(mediaProcessor.getDataOutput(), mediaLocator);
}
public static void main(String[] args) {
try {
MediaLocator locator = new MediaLocator("rtp://MY_PUBLIC_IP_HERE:10000/audio");
MediaTransmitter transmitter = new MediaTransmitter(locator);
System.out.println("-> Created media locator: '" + locator + "'");
File mediaFile = new File("D:\data\audio\posters.mp3");
DataSource source = Manager.createDataSource(new MediaLocator(mediaFile.toURL()));
System.out.println("-> Created data source: '" + mediaFile.getAbsolutePath() + "'");
// set the data source.
transmitter.setDataSource(source);
System.out.println("-> Set the data source on the transmitter");
// start transmitting the file over the network.
transmitter.startTransmitting();
System.out.println("-> Transmitting...");
System.out.println(" Press the Enter key to exit");
// wait for the user to press Enter to proceed and exit.
System.in.read();
System.out.println("-> Exiting");
transmitter.stopTransmitting();
} catch (Throwable t) {
t.printStackTrace();
}
System.exit(0);
}
}
,因为事实证明RTP是一种推动协议,因此使用相同的URL打开VLC中的流失败。然而