@Override public void actionPerformed(ActionEvent e) { // if the current image nb is less than the length of the video if (frameNumber < VIDEO_LENGTH) { // update current imagenb frameNumber++; try { // get next frame to send from the video, as well as its size int imageLength = video.getnextframe(buffer); // Builds an RTPpacket object containing the frame RTPpacket rtpPacket = new RTPpacket(MJPEG_TYPE, frameNumber, frameNumber * FRAME_PERIOD, buffer, imageLength); // get to total length of the full rtp packet to send int packetLength = rtpPacket.getLength(); // retrieve the packet bitstream and store it in an array of bytes byte[] packetBits = new byte[packetLength]; rtpPacket.getPacket(packetBits); // System.out.println("Send frame #" + imagenb); rtpTransport.send(packetBits, packetLength); // update GUI this.setChanged(); this.notifyObservers(Update.FRAME); } catch (IOException ex) { RTSPServer.log("I/O exception sending RTSP packet: %s\n", ex.getMessage()); return; } } else { // if we have reached the end of the video file, stop the timer timer.stop(); } }