package com.platform.listener;

import java.io.File;

import org.apache.commons.io.monitor.FileAlterationListener;
import org.apache.commons.io.monitor.FileAlterationMonitor;
import org.apache.commons.io.monitor.FileAlterationObserver;
import org.springframework.stereotype.Component;


/**
 * 
 * video 目录监控
 * 
 * @author yikaihong
 *
 */
public class VideoFileMonitor {

	private FileAlterationMonitor monitor = null;

	public VideoFileMonitor(long interval) {
		monitor = new FileAlterationMonitor(interval);
	}

	public void monitor(String path, FileAlterationListener listener) {
		FileAlterationObserver observer = new FileAlterationObserver(new File(path));
		monitor.addObserver(observer);
		observer.addListener(listener);
	}

	public void stop() throws Exception {
		monitor.stop();
	}

	public void start() throws Exception {
		monitor.start();
	}
	
//	public static void main(String[] args) throws Exception {
//		VideoFileMonitor m = new VideoFileMonitor(1000);
//        m.monitor("D:\\A", new VideoFileListener());
//        m.start();
//    }
	
}
