package com.wasu.statistics;

import android.media.MediaPlayer;

import com.wasu.comp.videoview.IMediaListener;
import com.wasu.cs.model.DemandProgram;
import com.wasu.cs.widget.videoview.WasuPlayerView;

public class PlayerStatistics implements IMediaListener {
	/**
	 * 播放器
	 */
	private WasuPlayerView player;
	private WasuStatistics statistics;
	public PlayerStatistics(DemandProgram mDemandProgram){
		statistics=WasuStatistics.getInstance();
	}
	public WasuPlayerView getPlayer() {
		return player;
	}

	public void setPlayer(WasuPlayerView player) {
		this.player = player;
	}
	@Override
	public void onAdStatusChanged(int arg0, int arg1) {

	}

	@Override
	public void onCompletion(MediaPlayer arg0) {
		statistics.bufferEnd();
	}

	@Override
	public void onError(MediaPlayer arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onInfo(MediaPlayer arg0, int arg1, int arg2) {
		if(arg1==MediaPlayer.MEDIA_INFO_BUFFERING_START){
			statistics.bufferBegin();
		}else if(arg1==MediaPlayer.MEDIA_INFO_BUFFERING_END){
			statistics.bufferEnd();
		}
	}

	@Override
	public void onPause(MediaPlayer arg0) {
		statistics.onPause();

	}

	@Override
	public void onPrepareComplete(MediaPlayer arg0) {
		statistics.prepareEnd();

	}

	@Override
	public void onPreparing(MediaPlayer arg0) {
		statistics.prepareBegin();

	}
	
	@Override
	public void onProgress(int arg0, int arg1, int arg2) {}

	@Override
	public void onResume(MediaPlayer arg0) {
		statistics.onResume();
	}

	@Override
	public void onSeekComplete(MediaPlayer arg0) {
		statistics.seekEnd();

	}

	@Override
	public void onSeeking(MediaPlayer arg0) {
		statistics.seekBegin();
	}

	@Override
	public void onStart(MediaPlayer arg0) {
		
	}

	@Override
	public void onStatusChanged(MediaPlayer arg0, int arg1) {
		
	}

	@Override
	public void onStop(MediaPlayer arg0) {
		if(arg0==null){
			statistics.playEnd(0,0);
			return;
		}
		statistics.playEnd(player.getCurrentPosition(),player.getDuration());
	}

	@Override
	public void onWasuError(int arg0, String arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onWasuPlayLimit(int arg0, String arg1) {
		// TODO Auto-generated method stub

	}

}
