
/*
 * This file is part of VLCJ.
 *
 * VLCJ is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VLCJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VLCJ.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright 2009, 2010, 2011, 2012, 2013 Caprica Software Limited.
 */

package clientetv;

import com.sun.jna.NativeLibrary;
import java.util.logging.Level;
import java.util.logging.Logger;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.headless.HeadlessMediaPlayer;


public class StreamRtp implements Runnable {

    public static void main(String[] args) throws Exception {

        NativeLibrary.addSearchPath("libvlc", "F:\\PDS\\ClienteTV\\VLC");
        
	StreamRtp canal1 = new StreamRtp ("01.mp4",formatRtpStream("225.0.0.1", 5555));
	Thread t1= new Thread(canal1);
        t1.start();
	StreamRtp canal2 = new StreamRtp ("02.avi",formatRtpStream("225.0.0.1", 5556));
        Thread t2= new Thread(canal2);
        t2.start();
	StreamRtp canal3 = new StreamRtp ("03.avi",formatRtpStream("225.0.0.1", 5557));
        Thread t3= new Thread(canal3);
        t3.start();
    }

    private static String formatRtpStream(String serverAddress, int serverPort) {
        StringBuilder sb = new StringBuilder(60);
        sb.append(":sout=#rtp{dst=");
        sb.append(serverAddress);
        sb.append(",port=");
        sb.append(serverPort);
        sb.append(",mux=ts}");
        return sb.toString();
    }

	public StreamRtp (String mrl, String opt){
		media = mrl;
		options = opt;
	}

	public void run(){
            System.out.println("Streaming '" + media + "' to '" + options + "'");

            MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
            HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();

            mediaPlayer.playMedia(media, options);
           try {
                // Don't exit
                Thread.currentThread().join();
            } catch (InterruptedException ex) {
                Logger.getLogger(StreamRtp.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
	private String options;
	private String media;
}