首先,我们来看一下TCPMP的播放模块的结构定义:
static const nodedef Player =
{
sizeof(player_base)|CF_GLOBAL|CF_SETTINGS,
PLAYER_ID,
NODE_CLASS,
PRI_MAXIMUM+600,
(nodecreate)Create,
(nodedelete)Delete,
};
绝大多数节点都有一个对应的数据对象,记录该节点的数据和方法,每一个子节点对象都是以父节点对象作为该节点一个元素,类似C++的封装继承机制。如果子节点的父节点没有数据对象,该节点可以从node节点直接继承。每一个节点都可以看成Node节点的直接或间接子节点,所以所有节点头以一个相同的node结构开头,子节点可能还有自己的属性,在继承父对象后就是子节点自己的元素。
typedefstruct node
{
intClass;
nodeenumEnum;
nodegetGet;
nodesetSet;
} node;
Class表示该对象的标识,如PLAYER_ID。
Enum是一个函数指针,指向一个函数用于枚举当前节点的属性。
Get是一个函数指针,得到当前节点某一属性值。
Set是一个函数指针,设置当前节点的某一属性数值。
下面我们来看看struct node* Player;
首先我们如下般获得Player:
context* p = Context();
player* myplayer = NULL;
if(p) Moonplayer = (player*)(p->Player);
然后我们就可以通过Moonplayer来进行播放的控制了。例如Get可以获得播放的一些属性和状态,Set可以设定播放的属性和状态。
下表列出了Moonplayer控制的相关播放属性:(play.h)
// buffer size in KB (int)
#define PLAYER_BUFFER_SIZE0x20
// microdrive buffer size in KB (int)
#define PLAYER_MD_BUFFER_SIZE 0x80
// microdrive mode (bool_t)
#definePLAYER_MICRODRIVE 0x21
// repeat (bool_t)
#definePLAYER_REPEAT0x22
// shuffle (bool_t)
#definePLAYER_SHUFFLE0x23
// start play after open (bool_t)
#definePLAYER_PLAYATOPEN 0x24
// start play after open in fullscreen (bool_t)
#definePLAYER_PLAYATOPEN_FULL 0x7B
// exit at the end (bool_t)
#define PLAYER_EXIT_AT_END0xB9
// keep playlist after WND set null (bool_t)
#definePLAYER_KEEPLIST0x48
// play or pause (bool_t)
#definePLAYER_PLAY0x32
// play speed (fraction)
#definePLAYER_PLAY_SPEED 0x3F
// fastforward (bool_t)
#definePLAYER_FFWD0x49
// fastforward speed (fraction)
#definePLAYER_FFWD_SPEED 0x4A
// position in fraction (fraction)
#definePLAYER_PERCENT0x25
// position in time (tick_t)
#definePLAYER_POSITION0x28
// duration (tick_t)
#definePLAYER_DURATION0x46
// timer shown on screen (tchar_t[])
#definePLAYER_TIMER0x7E
// show left time (bool_t)
#definePLAYER_TIMER_LEFT 0x7F
// benchmark duration (tick_t)
#definePLAYER_BENCHMARK0x55
// benchmark video source size (point)
#define PLAYER_BENCHMARK_SRC 0xB6
// benchmark video dest size (point)
#define PLAYER_BENCHMARK_DST 0xB7
// display name (tchar_t[])
#definePLAYER_TITLE0x29
// current format (format*)
#definePLAYER_FORMAT0x2B
// current stream (stream*)
#definePLAYER_INPUT0x2A
// current audio stream (int)
#definePLAYER_VSTREAM0x76
// current video stream (int)
#definePLAYER_ASTREAM0x77
// current subtitle stream (int)
#definePLAYER_SUBSTREAM0x82
// current audio output class (int)
#definePLAYER_AOUTPUTID0x83
// current video output class (int)
#definePLAYER_VOUTPUTID0x84
// highest priorty audio output class (readonlyint)
#define PLAYER_AOUTPUTID_MAX 0xA0
// highest priorty video output class (readonlyint)
#define PLAYER_VOUTPUTID_MAX 0xA1
// current audio output (node*)
#definePLAYER_AOUTPUT0x2C
// current video output (node*)
#definePLAYER_VOUTPUT0x2D
// number of files in playlist (int)
#definePLAYER_LIST_COUNT 0x2E
// current file in playlist (int)
#define PLAYER_LIST_CURRENT 0x2F
// current file index (suffled) in playlist(int)
#define PLAYER_LIST_CURRIDX 0xA2
// fullscreen zoom factor (fraction_t)
#definePLAYER_FULL_ZOOM0x35
// skin mode zoom factor (fraction_t)
#definePLAYER_SKIN_ZOOM0x36
// bilinear zoom (bool_t)
#definePLAYER_SMOOTH500x47
// bilinear zoom (bool_t)
#define PLAYER_SMOOTHALWAYS 0x7A
// fullscreen direction flags (int)
#definePLAYER_FULL_DIR0x39
// non fullscreen direction flags (int)
#definePLAYER_SKIN_DIR0x45
// current relative dir (readonly) (int)
#definePLAYER_REL_DIR0x7D
// overlay is on top or clipping needed(bool_t)
#definePLAYER_CLIPPING0x3B
// skin viewport rectangle (rect)
#define PLAYER_SKIN_VIEWPORT 0x3C
// prerotate portrait movies
#define PLAYER_AUTOPREROTATE 0x3D
// fullscreen mode (bool_t)
#definePLAYER_FULLSCREEN 0x3E
// volume volume (int 0..100)
#definePLAYER_VOLUME0x40
// volume mute (bool_t)
#definePLAYER_MUTE0x41
// panning (int -128..128)
#definePLAYER_PAN0x9D
// preamp (int -128..128)
#definePLAYER_PREAMP0x9E
// audio quality (int 0..2)
#define PLAYER_AUDIO_QUALITY 0x42
// auto video quality (int 0..2)
#define PLAYER_VIDEO_QUALITY 0xBC
// video idct acceleration (bool_t)
#define PLAYER_VIDEO_ACCEL0x44
// keep audio playing in background
#define PLAYER_KEEPPLAY_AUDIO 0x63
// keep video playing in background
#define PLAYER_KEEPPLAY_VIDEO 0x72
#define PLAYER_SHOWINBACKGROUND 0xBF
#define PLAYER_SINGLECLICKFULLSCREEN 0xC0
// microdrive start at in KB (int)
#definePLAYER_BURSTSTART 0xA3
// how much to load (%)
#definePLAYER_UNDERRUN0x67
// how much to load for audio (int)
#define PLAYER_AUDIO_UNDERRUN 0xBB
// move back step time (tick_t)
#define PLAYER_MOVEBACK_STEP 0x68
// move ffwd step time (tick_t)
#define PLAYER_MOVEFFWD_STEP 0x7C
// stereo enum (int)
#definePLAYER_STEREO0x74
// aspect ratio(frac)
#definePLAYER_ASPECT0xBE
// application sent to background(bool_t)
#definePLAYER_BACKGROUND 0x98
// player window is foreground(bool_t)
#definePLAYER_FOREGROUND 0xB4
// set before and after sleep(bool_t)
#definePLAYER_POWEROFF0xB5
// video caps
#definePLAYER_VIDEO_CAPS 0x64
// discard saved playlist (bool)
#define PLAYER_DISCARDLIST0xBA
// video output is a real overlay, readonly(bool_t)
#define PLAYER_VIDEO_OVERLAY 0xBD
// player status
#definePLAYER_SYNCING0x81
#definePLAYER_LOADMODE0x96
#definePLAYER_STREAMING0xB8
// notify pin for interface
#definePLAYER_NOTIFY0x97
// on list changed event
#define PLAYER_LIST_NOTIFY0x78
// for open dialog
#definePLAYER_CURRENTDIR 0x6D
// commands:
// update video settings
#define PLAYER_UPDATEVIDEO0x90
// update equalizer settings
#define PLAYER_UPDATEEQUALIZER 0xA5
// begin screen rotation (turn off video)
#define PLAYER_ROTATEBEGIN0x91
// end screen rotation
#definePLAYER_ROTATEEND0x92
// reset video driver
#definePLAYER_RESETVIDEO 0x93
// codec notify about not supported data (pin)
#define PLAYER_NOT_SUPPORTED_DATA 0x9F
// move back
#definePLAYER_MOVEBACK0x9A
// move forward
#definePLAYER_MOVEFFWD0x9B
// position bar moving state (boolean)
#definePLAYER_INSEEK0x9C
// next chapter/track
#definePLAYER_NEXT0xB0
// prev chapter/track
#definePLAYER_PREV0xB1
// stop
#definePLAYER_STOP0xB2
// resync
#definePLAYER_RESYNC0xB3
// array type params (just a hint)
#definePLAYER_ARRAY0x1000
// url in playlist (0x1000,0x1001,0x1002...)
#definePLAYER_LIST_URL0x1000
// title in playlist (0x2000,0x2001,0x2002...)
#definePLAYER_LIST_TITLE 0x2000
// title or filename in playlist
#define PLAYER_LIST_AUTOTITLE 0x5000
// length in playlist (0x4000,0x4001,0x4002...)
#define PLAYER_LIST_LENGTH0x4000
// input comments
#definePLAYER_COMMENT0x3000
举个例子:
播放的的话,我们可以如下设置:
Bool_tb=1;
Moonplayer->Set(Moonplayer,PLAYER_PLAYER,&b,sizeof(b));
停止的话,可以是:
Bool_t b=0;
Moonplayer->Set(Moonplayer,PLAYER_PLAYER,&b,sizeof(b));
其他播放类似,可以参考TCPMP或者我程序中的代码。