Я использую JMF для потоковой передачи видео с NVR, я передаю правильный URL (работал в другой библиотеке), я получаю «Неверный адрес сервера».Может ли кто-нибудь помочь мне в этом?или предоставьте мне пример кода Java-клиента RTSP JMF.
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.io.IOException;
import java.net.MalformedURLException;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.RealizeCompleteEvent;
import javax.media.StartEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import com.sun.media.rtsp.RtspManager;
import com.sun.media.rtsp.RtspUrl;
public class RTSPclient extends JFrame implements ControllerListener {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel jPanel_Video = null;
Player player = null;
String url = null;
MediaLocator mrl = null;
Component visualComp = null;
private JPanel getJPanel_Video() {
if (jPanel_Video == null) {
jPanel_Video = new JPanel();
jPanel_Video.setLayout(new BorderLayout());
jPanel_Video.setBounds(new Rectangle(4, 3, 448, 333));
}
return jPanel_Video;
}
/**
* @throws MalformedURLException *******************************************************/
void setLocation() throws MalformedURLException{
String startDate = "20181217T074041";
String endDate = "20181217T075439";
String x = "rtsp://XXX:XXX@192.168.0.14:558/PlaybackChannel/0/media.smp/start=" + startDate + "&end=" + endDate;
System.out.println(" MRL: " + x);
mrl= new MediaLocator(x);
if (mrl == null) {
System.err.println("Can't build MRL");
System.exit(1);
}
}
/******************/
void realizeRTSP(){
try {
player = Manager.createPlayer(mrl);
} catch (NoPlayerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
player.addControllerListener(this);
player.realize();
}
/******************/
public synchronized void controllerUpdate(ControllerEvent evt){
System.out.println(evt.toString());
if(evt instanceof StartEvent){
Player p = (Player) evt.getSourceController();
visualComp = p.getVisualComponent();
if (visualComp != null){
Dimension d = visualComp.getPreferredSize();
jPanel_Video.setSize(d);
jPanel_Video.add("North", p.getVisualComponent());
jPanel_Video.setVisible(true);
validate();
}
}
if(evt instanceof RealizeCompleteEvent){
player.start();
}
}
/*********************************************************/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
RTSPclient thisClass = new RTSPclient();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
public RTSPclient() {
super();
initialize();
}
private void initialize() {
try {
this.setSize(465, 369);
this.setContentPane(getJContentPane());
this.setTitle("RTSP Player");
setLocation();
realizeRTSP();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJPanel_Video(), null);
}
return jContentPane;
}
}