?? inputfile.cpp
字號:
/**************************************************************************************
* *
* *
**************************************************************************************/
#include "InputFile.h"
/*
*
* ——讀本地文件
*
*/
/*
* 構(gòu)造器
* ------
*
*
*
*/
MediaInputFile::MediaInputFile()
{
this->file = NULL;
}
/*
* 析構(gòu)器
* ------
*
*
*
*/
MediaInputFile::~MediaInputFile()
{
}
/*
*
* ——得到媒體項(xiàng)的類型
*
*/
media_type_t MediaInputFile::GetType()
{
return MEDIA_TYPE_INPUT;
}
/*
*
* ——得到媒體項(xiàng)的類型的名稱
*
*/
char *MediaInputFile::GetName()
{
return "FILE Input";
}
/*
* Connect:
* --------
*
* ——不接受
*
*/
MP_RESULT MediaInputFile::Connect(MediaItem *item)
{
return MP_RESULT_ERROR;
}
MP_RESULT MediaInputFile::ReleaseConnections()
{
return MP_RESULT_ERROR;
}
DWORD MediaInputFile::GetCaps()
{
return 0;
}
MP_RESULT MediaInputFile::Configure(HINSTANCE hInstance, HWND hwnd)
{
return MP_RESULT_ERROR;
}
/*
*
* ——打開文件
*
*/
MP_RESULT MediaInputFile::Open(char *url, media_input_mode_t mode)
{
this->file = NULL;
if(url != NULL) {
switch(mode) {
case INPUT_OPEN_BINARY:
this->file = fopen(url, "rb");
break;
case INPUT_OPEN_ASCII:
this->file = fopen(url, "rt");
break;
default:
this->file = fopen(url, "rb");
break;
}
}
if(this->file == NULL) {
return MP_RESULT_ERROR;
}
/*
* 得到文件大小
*/
this->Seek(0, INPUT_SEEK_END);
this->size = this->Seek(0, INPUT_SEEK_CUR);
this->Seek(0, INPUT_SEEK_SET);
return MP_RESULT_OK;
}
long MediaInputFile::GetSize()
{
return MP_RESULT_ERROR;
}
long MediaInputFile::GetBufferSize()
{
return MP_RESULT_ERROR;
}
long MediaInputFile::GetBufferPosition()
{
return MP_RESULT_ERROR;
}
long MediaInputFile::GetBufferingSize()
{
return MP_RESULT_ERROR;
}
/*
*
* ——讀某些二進(jìn)制數(shù)據(jù)
*
*/
unsigned int MediaInputFile::Read(MediaBuffer *mb, unsigned int size)
{
if(!mb || !this->file)
return MP_RESULT_ERROR;
if(size > mb->GetSize())
mb->ReAlloc(size);
return fread(mb->GetData(), 1, size, this->file);
}
/*
*
* ——在文件中搜索
*
*/
unsigned int MediaInputFile::Seek(int size, media_input_seek_t method)
{
if(!this->file)
return MP_RESULT_ERROR;
switch(method) {
case INPUT_SEEK_SET:
return fseek(this->file, size, SEEK_SET);
break;
case INPUT_SEEK_CUR:
if(size == 0) {
return ftell(this->file);
}
else {
return fseek(this->file, size, SEEK_CUR);
}
break;
case INPUT_SEEK_END:
return fseek(this->file, size, SEEK_END);
break;
}
return MP_RESULT_ERROR;
}
/*
*
* ——得到完整的行
*
*/
unsigned int MediaInputFile::GetLine(MediaBuffer *mb)
{
if(!this->file)
return MP_RESULT_ERROR;
fgets((char *) mb->GetData(), mb->GetSize(), this->file);
return MP_RESULT_OK;
}
/*
*
* ——文件結(jié)束則返回真
*
*/
BOOL MediaInputFile::EndOfFile()
{
if(!this->file)
return TRUE;
return feof(this->file);
}
/*
*
* ——關(guān)閉文件
*
*/
MP_RESULT MediaInputFile::Close()
{
if(!this->file)
return MP_RESULT_ERROR;
fclose(this->file);
return MP_RESULT_OK;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -