Video fayllar bilan ishlash

|
Video fayllar bilan ishlash
|
bet | 16/17 | Sana | 18.05.2024 | Hajmi | 0,95 Mb. | | #242188 |
Bog'liq I bob c builder dasturining grafik imkoniyatlari 6
MediaPlayer komponentasidan foydalaninb videoroliklarni koʻrish uchun moʻljallangan forma koʻrinishi quyidagicha:
3.4. Rasm. Video fayllar bilan ishlovchi dastur formasining koʻrinishi
Quyida videorolikni koʻrishga moʻljallangan dastur matnini keltiramiz:
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
#define MINUTE(ms) ((ms/1000)/60)
#define SECOND(ms) ((ms/1000)%60)
Graphics::TBitmap *fcmPlay,*kmPlay, *bmPlay; // Play
Graphics::TBitmap *fcmPause,*bmPause; // Pause
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
bmPlay = new Graphics::TBitmap();
bmPause = new Graphics::TBitmap();
SpeedButton2->Glyph->Assign(bmPlay);
MediaPlayer1->Display = Form1;}
void _fastcall GetFrameSize (AnsiString f, int *w, int *h)
{ if ( f.Pos(".avi") == 0 )
{ *w = 352;
*h = 240;
struct {
char RIFF[4];
long int nu_1[5];
char AVIH[4];
long int nu_2[9];
long int w;
long int h;
} header;
TFileStream *fs;
fs = new TFileStream(f,fmOpenRead) ;
fs->Read(&header, sizeof(header));
*w = header.w;
*h = header.h;
delete fs; } }
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{ int fw, fh;
int top,left;
int sw, sh;
int mw, mh;
float kw, kh;
float k;
OpenDialog1->Title = "Tanlash";
OpenDialog1->InitialDir = "";
OpenDialog1->Filter =
"Bсе файлы|*.avi;*.mpg;*.mpegI"
"AVI|*.avi|MPG|*.mpg|MGEG|*.mpeg";
if ( ! OpenDialog1->Execute() )
return;
if ( MediaPlayer1->FileName==OpenDialog1->FileName )
return;
GetFrameSize(OpenDialog1->FileName,&fw, &fh);
mw = Form1->ClientWidth;
mh = Form1->Panel1->Top-10;
if ( fw < mw )
kw = 1;
else kw = (float) mw / fw;
if ( fh < mh )
kh = 1; else kh = (float) mh / fh;
if ( kw < kh )
k = kw;
else k = kh;
sw = fw * k;
sh=fh*k;
left = (Form1->ClientWidth - sw) / 2;
top = (Panel1->Top - sh) / 2;
MediaPlayer1->FileName = OpenDialog1->FileName;
MediaPlayer1->Open();
MediaPlayer1->DisplayRect = Rect(left-400,top+20,sw-400,sh-110);
Form1->Canvas->FillRect(Rect(0,0,ClientWidth,Panel1->Top));
SpeedButton2->Enabled = true;
MediaPlayer1->TimeFormat = tfMilliseconds;
int ms = MediaPlayer1->Length;
AnsiString st = IntToStr(SECOND(ms));
if ( st.Length() == 1)
st = "0" + st;
st = IntToStr(MINUTE(ms)) + ":" + st;
Label1->Caption = st;
Label3->Caption = "0:00";
SpeedButton2->Glyph->Assign(bmPause);
SpeedButton2->Hint = "Pause";
SpeedButton2->Tag = 1;
SpeedButton1->Enabled = False;
MediaPlayer1->Play();
Timer1->Enabled = true ;}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton2Click(TObject *Sender)
{ if (SpeedButton2->Tag == 0)
{ SpeedButton2->Glyph->Assign(bmPause);
SpeedButton2->Hint = "Pause";
SpeedButton2->Tag = 1;
SpeedButton1->Enabled = False; // êíîïêà Eject
MediaPlayer1->Play();
Timer1->Enabled = true;}
else {
MediaPlayer1->Stop();
SpeedButton2->Glyph->Assign(bmPlay);
SpeedButton2->Hint = "Play";
SpeedButton2->Tag = 0;
SpeedButton1->Enabled = True;
Timer1->Enabled = false; } }
//---------------------------------------------------------------------------
void __fastcall TForm1::MediaPlayer1Notify(TObject *Sender)
{ if ( ( MediaPlayer1->Mode == mpStopped ) &&
( SpeedButton2->Tag == 1))
{ Timer1->Enabled= false;
SpeedButton2->Glyph->Assign(bmPlay);
SpeedButton2->Hint = "Play";
SpeedButton2->Tag = 0;
SpeedButton1->Enabled = True; } }
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{ if ( MediaPlayer1->Mode == mpStopped )
{ MediaPlayer1->Position = 1;
MediaPlayer1->Position = 0;
} }
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{ MediaPlayer1->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{ MediaPlayer1->TimeFormat = tfMilliseconds;
int ms = MediaPlayer1->Position;
AnsiString st = IntToStr(SECOND(ms));
if ( st.Length() == 1)
st = "0" + st;
st = IntToStr(MINUTE(ms)) + ":" + st;
Label3->Caption = st;
}
Dastur ishga tushirilgach, kerakli video faylni tanlab, uning namoyishini boshlash mumkin:
3.5. Rasm. Video fayllar bilan ishlovchi dastur natijasi
Bu kabi dasturiy vositalar yordamida audio va video fayllar bilan ishlovchi dasturlarning qoʻllanmalilik darajasini oshirish, foydalanuvchu istagidan kelib chiqib, oʻzgartirishlar kiritish mumkin.
XULOSA
Ushbu bitiruv malakaviy ishida qoʻyilgan “C++ tilining multimedia imkoniyatlari” mavzusi ostida qoʻyilgan maqsad va vazifalarni bajarish davomida quyidagi natijalarga erishildi:
C++ tilining grafika va multimedia bilan ishlovchi komponentalari batafsil oʻrganib chiqildi va ish tarkibiga kiritildi;
Ishda grafik asos va asosiy grafik primitivlar haqida umumiy tushunchalar keltirildi;
Tasvirlarni tashqi fayldan oʻqish va bitli tasvirlar bian ishlash toʻgʻrisida ma’lumotlar keltirildi va amaliy masalalar yordamida yoritildi;
Multiplikatsiyalar hosil qilish jarayoni oʻrganib chiqildi va amaliy dasturiy vositalar yordamida yoritildi;
C++ tilida ovozli va ovozsiz animatsiyalar bilan ishlovchi Animate va MediaPlayer komponentalarining xususiyatlari va imkoniyatlari oʻrganib chiqildi va ishda keltirildi;
Koordinatalar sistemasini boshqaruvchi Chart koordinatasi imkoniyatlari oʻrganildi va bu komponenta yordamida bitta koordinatalar sistemasida bir nechta funksiyalarning grafiklarini quruvchi dasturiy vosita yaratildi;
MediaPlayer komponentasidan foydalangan hold ovozli fayllarni ijro etuvchi dasturiy vosita yaratildi va ish tarkibiga kiritildi;
Video fayllarni ijro etuvchi dastur yaratildi va ish tarkibiga kiritildi.
Ushbu bitiruv ishida tuzilgan animatsiyani, ovozli ijroni, video tasvirni boshqarishga moʻljallangan dasturiy vositalardan foydalanib, multimdiali elektron oʻquv qoʻllanmalar yaratish va audio va videopleyer dasturlarining qoʻllanmalilik darajasini yuksaltirish kabi ishlarni amalga oshirish mumkin.
|
| |