raismth.ns(function() { with (raismth.LIB) {
myDump("[RAISMTH] mplayer module initialization\n");
var resume = new Array();
theApp.mplayer = {
	fifo_init : function(indice){
		let success = false;
		let fifo = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
		try{
			fifo.initWithPath('/tmp/mplayer-fifo-' + indice);
		} catch(e) {
			myDump('[RAISMTH] Exception : mplayer-fifo : ' + e + '\n');
		} 
		finally {
			if(fifo.exists()) {
				myDump('[RAISMTH] Mplayer fifo file detected /tmp/mplayer-fifo-' + indice + '\n');
				success = fifo;
			} else {
				myDump('[RAISMTH] Mplayer fifo file not detected /tmp/mplayer-fifo-' + indice + '\n');
			}
		}
		return success;
	},
/*
	monitor : function(indice, delta) {					  
		myDump('[RAISMTH] mplayer monitor\n');			  
		let counter = raismth.chunks[indice];
		myDump('[RAISMTH] monitor counter: ' + counter + ' delta: ' + delta + '\n');
		
		if(delta < 5000 && (counter > 10 && !resume[indice])) {
			myDump('[RAISMTH] Stream ' + indice + ' paused\n');
			raismth.ctrlTimers[indice] = 3;
			myDump('[RAISMTH] mplayer monitor calling management\n');
			raismth.mplayer.management(indice, true);
			resume[indice] = true;
		} else if(counter > 10 && delta > 10000 && resume[indice]) {
			myDump('[RAISMTH] Stream ' + indice + ' unpaused\n');
			raismth.ctrlTimers[indice] = 0;
			myDump('[RAISMTH] mplayer monitor calling management else\n');
			raismth.mplayer.management(indice, true);
			resume[indice] = false;			
		}		
	},      
*/
	player_control : function(cmd,fifo) {
		if(fifo != false) {
			try{
				// alert(cmd);
				let stream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
				let data = cmd + '\n';
				stream.init(fifo, 0x02 | 0x10, 0666, 0);
				stream.write( data, data.length );
	
				if (stream instanceof Ci.nsISafeOutputStream) {  
					stream.finish();  
				} else {  
					stream.close();  
				}
			} catch(e) {
				myDump('[RAISMTH] Exception: ' + e + '\n');
			}
		}
	},
/*
	management : function(indice, resume) {
		myDump('[RAISMTH] mplayer management\n');			     
		if(raismth.mplayer_fifo) {
			let fifo = null; // raismth.mplayer.fifo_init(indice);
			if(raismth.player_istances[indice] && raismth.player_istances[indice].isRunning) {
				let counter = raismth.ctrlTimers[indice];
				let cmd = '';
				myDump('[RAISMTH] Network Monitor : Network slowdown counter: ' + counter + '\n');
				
				switch(counter) {
					case 0:
						if(resume) {
							fifo = raismth.mplayer.fifo_init(indice);
							if(fifo != false) {
								raismth.ctrlTimers[indice] = false;
								cmd = 'osd_show_text "Playing..." 2000';
								raismth.mplayer.player_control(cmd,fifo);
							}
						}
						break;
					case 1:
						// nope
						raismth.slobj[indice].stato('MP->MONITOR', 'Network Slowdown...', 1);
						break;
				
					case 2:
						fifo = raismth.mplayer.fifo_init(indice);
						if(fifo != false) {
							cmd = 'osd_show_text "Network slowdown..." 2000';
							raismth.mplayer.player_control(cmd,fifo);
							raismth.slobj[indice].stato('MP->MONITOR', 'Network Slowdown [2]...', 1);
						}
						break;		
					case 3:
						fifo = raismth.mplayer.fifo_init(indice);
						if(fifo != false) {
							raismth.slobj[indice].stato('MP->MONITOR', 'Network Slowdown, buffering...', 1);
							myDump('[RAISMTH] Network Monitor : Network slowdown, buffering\n');
							cmd = 'osd_show_text "Buffering..." 15000';
							raismth.mplayer.player_control(cmd,fifo);
							cmd = 'pause';
							raismth.mplayer.player_control(cmd,fifo);
						}
						break;
				}
				raismth.ctrlTimers[indice]++;
			} else {
				raismth.ctrlTimers[indice] = false;
			}
		}
	},
*/
}
}});
