#include "Player.h"

BEGIN_EVENT_TABLE(Player,wxPanel)
	EVT_TIMER(ID_TIMER,Player::onTimer)
END_EVENT_TABLE()

Player::Player( wxWindow *parent, wxWindowID winid /*= wxID_ANY */, const wxPoint& pos /*= wxDefaultPosition */, const wxSize& size /*= wxDefaultSize */, long style /*= wxTAB_TRAVERSAL | wxNO_BORDER*/, const wxString& name /*= wxPanelNameStr*/ )
:timer(this,ID_TIMER), PlayerUI(parent,winid,pos,size,style)
{
	customCreation();
}
Player::~Player(void)
{
}

void Player::customCreation()
{
	playButton->SetBitmapLabel(wxIcon(media_playback_start_xpm));
	stopButton->SetBitmapLabel(wxIcon(media_playback_stop_xpm));
	skipBackwardButton->SetBitmapLabel(wxIcon(media_skip_backward_xpm));
	skipForwardButton->SetBitmapLabel(wxIcon(media_skip_forward_xpm));
	forwardButton->SetBitmapLabel(wxIcon(media_seek_forward_xpm));
	rewindButton->SetBitmapLabel(wxIcon(media_seek_backward_xpm));
}


void Player::onTimer( wxTimerEvent & evt )
{
	if(capture->isPlaying()) {
		capture->nextFrame();
		progressSlider->SetValue(capture->getVideoPositionRatio());
		refreshCanvas();
	}
}

void Player::onSliderScroll( wxScrollEvent & evt )
{
	capture->setVideoPositionRatio(progressSlider->GetValue());
}

void Player::onStop( wxCommandEvent & evt )
{
	capture->stop();
	playButton->SetBitmapLabel(wxIcon(media_playback_start_xpm));
}

void Player::onPlay( wxCommandEvent & evt )
{
	capture->playOrPause();

	if(capture->isPlaying())
		playButton->SetBitmapLabel(wxIcon(media_playback_pause_xpm));
	else
		playButton->SetBitmapLabel(wxIcon(media_playback_start_xpm));
}

void Player::onRewindButtonClick( wxCommandEvent& event )
{
	capture->rewind();
	refreshCanvas();
}

void Player::onForwardButtonClick( wxCommandEvent& event )
{
	capture->forward();
	refreshCanvas();
}