main.cc
来自「linux下的flash的播放源代码」· CC 代码 · 共 377 行
CC
377 行
/////////////////////////////////////////////////////////////// Flash Plugin and Player// Copyright (C) 1998 Olivier Debon// // This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.// // This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// // You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.// ///////////////////////////////////////////////////////////////// Author : Olivier Debon <odebon@club-internet.fr>// #include <stdio.h>#include <stdlib.h>#include <sys/time.h>#include <sys/types.h>#include <unistd.h>#include <sys/ipc.h>#include <sys/shm.h>#include <signal.h>#include "flash.h"#include <string.h>#include <pthread.h>#include <semaphore.h>#include <sys/wait.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#define WIDTH_BORDER 2 #define HEIGHT_CAPTION 16static int timer_counter = 0;extern int soundId; extern int frameId; typedef struct { FlashDisplay fd; HWND hwnd; PBITMAP bmp; // Graphic buffer} MgContext;MgContext xc1, *xc=&xc1;long FlashGraphicInitMg(FlashHandle fh, HWND hWnd){ HDC hdc; BITMAP* bmp; RECT rc; hdc = GetClientDC(hWnd); bmp = (BITMAP*)malloc(sizeof(BITMAP)); memset(bmp, 0, sizeof(bmp)); bmp->bmBits = NULL; GetClientRect(hWnd, &rc); GetBitmapFromDC (hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, bmp); xc->fd.pixels = (char*)bmp->bmBits; xc->fd.width = bmp->bmWidth; xc->fd.height = bmp->bmHeight; xc->fd.bpl = bmp->bmPitch; xc->fd.depth = bmp->bmBitsPerPixel; xc->hwnd = hWnd; xc->bmp = bmp; ReleaseDC(hdc); return FlashGraphicInit(fh, &xc->fd);}void FlashCopyMg(void){ HDC hdc; hdc = GetClientDC(xc->hwnd);#if 0 FillBoxWithBitmapPart(hdc, xc->fd.clip_x, xc->fd.clip_y, xc->fd.clip_width, xc->fd.clip_height, 0, 0, xc->bmp, xc->fd.clip_x, xc->fd.clip_y);#else FillBoxWithBitmap(hdc, 0, 0, xc->fd.width, xc->fd.height, xc->bmp);#endif ReleaseDC(hdc);}/* * This file is the entry of a very simple Flash Player */struct FlashInfo fi;char *filename;intreadFile(char *filename, char **buffer, long *size){ FILE *in; char *buf; long length; in = fopen(filename,"r"); if (in == 0) { perror(filename); return -1; } fseek(in,0,SEEK_END); length = ftell(in); rewind(in); buf = (char *)malloc(length); fread(buf,length,1,in); fclose(in); *size = length; *buffer = buf; return length;}voidshowUrl(char *url, char *target, void *client_data){ printf("GetURL : %s\n", url);}voidgetSwf(char *url, int level, void *client_data){ FlashHandle flashHandle; char *buffer; long size; flashHandle = (FlashHandle) client_data; printf("LoadMovie: %s @ %d\n", url, level); if (readFile(url, &buffer, &size) > 0) { FlashParse(flashHandle, level, buffer, size); }}FlashHandle flashHandle; //hzint FlashPlayerProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ HDC hdc; struct timeval wd; long cmd; long wakeUp; char msg[1024]; FlashEvent fe; int skip; switch (message) { case MSG_PAINT: fe.type = FeRefresh; FlashExec(flashHandle, FLASH_EVENT, &fe, &wd); break; case MSG_TIMER: skip = (int)wParam; while(skip > 0) { cmd = FLASH_STEP; wakeUp = FlashExec(flashHandle, cmd, 0, &wd); skip--; } cmd = FLASH_WAKEUP; wakeUp = FlashExec(flashHandle, cmd, 0, &wd); if (xc->fd.flash_refresh) { FlashCopyMg(); xc->fd.flash_refresh = 0; } break; case MSG_KEYDOWN: if (wParam == SCANCODE_ENTER) { cmd = FLASH_EVENT; fe.key = FeKeyEnter; } wakeUp = FlashExec(flashHandle, cmd, &fe, &wd); break;#if 0 case MSG_CHAR: printf("char = %c %d\n", (char)wParam, (int)wParam); switch ((int)wParam){ case 10: //Enter cmd = FLASH_EVENT; fe.key = FeKeyEnter; break; } wakeUp = FlashExec(flashHandle, cmd, &fe, &wd); break;#endif case MSG_LBUTTONDOWN: fe.type = FeButtonPress; FlashExec(flashHandle, FLASH_EVENT, &fe, &wd); break; case MSG_LBUTTONUP: fe.type = FeButtonRelease; FlashExec(flashHandle, FLASH_EVENT, &fe, &wd); break; case MSG_MOUSEMOVE: fe.type = FeMouseMove; fe.x = LOWORD (lParam); fe.y = HIWORD (lParam); FlashExec(flashHandle, FLASH_EVENT, &fe, &wd); break; case MSG_CLOSE: if (MessageBox (hWnd, "Do you really want to quit?", "FlashPlayer", MB_YESNO | MB_ICONQUESTION) == IDNO) break; DestroyMainWindow (hWnd); PostQuitMessage (hWnd); return 0; default: break; } return DefaultMainWinProc(hWnd, message, wParam, lParam);}static void sigalarm (int v){ timer_counter++;} static BOOL SetClientTimer (int t){ struct sigaction siga; struct itimerval timerv; siga.sa_handler = sigalarm; siga.sa_flags = 0; memset (&siga.sa_mask, 0, sizeof (sigset_t)); sigaction (SIGALRM, &siga, NULL); timerv.it_interval.tv_sec = 0; timerv.it_interval.tv_usec = t; timerv.it_value = timerv.it_interval; if (setitimer (ITIMER_REAL, &timerv, NULL)) return FALSE; return TRUE;}static void InitCreateInfo(PMAINWINCREATE pCreateInfo){ pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE; pCreateInfo->dwExStyle = WS_EX_IMECOMPOSE; pCreateInfo->spCaption = "flash player"; pCreateInfo->hMenu = 0; pCreateInfo->hCursor = LoadCursorFromFile ("arrow.cur"); pCreateInfo->hIcon = 0; pCreateInfo->MainWindowProc = FlashPlayerProc; pCreateInfo->lx = 0; pCreateInfo->ty = 0; pCreateInfo->rx = fi.frameWidth/20 + WIDTH_BORDER * 2; pCreateInfo->by = fi.frameHeight/20 + WIDTH_BORDER * 2 + HEIGHT_CAPTION; pCreateInfo->iBkColor = COLOR_lightwhite; pCreateInfo->dwAddData = 0; pCreateInfo->hHosting = HWND_DESKTOP;}int MiniGUIMain(int argc, const char* argv[]){ char *buffer; long size; int status; MSG Msg; MAINWINCREATE CreateInfo; HWND hMainWnd; int speed, i; int ig = 1; static int skip = 0; if (argc < 2) { fprintf(stderr,"Usage : %s <file.swf>\n", argv[0]); exit(1); } filename = (char *)argv[1]; if (readFile(filename, &buffer, &size) < 0) { exit(2); } flashHandle = FlashNew(); if (flashHandle == 0) { exit(1); } // Load level 0 movie do { status = FlashParse(flashHandle, 0, buffer, size); } while (status & FLASH_PARSE_NEED_DATA); free(buffer); FlashGetInfo(flashHandle, &fi); if(fi.frameWidth/20 < 400 && fi.frameHeight/20 < 300) { fi.frameWidth *= 2; fi.frameHeight *= 2; } #ifdef _LITE_VERSION SetDesktopRect (0, 0, fi.frameWidth/20 + 4 , fi.frameHeight/20 + 20);#endif InitCreateInfo(&CreateInfo); hMainWnd = CreateMainWindow(&CreateInfo); if (hMainWnd == HWND_INVALID) return -1; FlashGraphicInitMg(flashHandle, hMainWnd);// FlashSoundInit(flashHandle, "/dev/dsp"); FlashSetGetUrlMethod(flashHandle, showUrl, 0); FlashSetGetSwfMethod(flashHandle, getSwf, (void*)flashHandle); speed = 1000000/fi.frameRate; if( !(SetClientTimer(speed)) ) printf("setitimer fail\n"); while( GetMessage(&Msg, hMainWnd) ) { TranslateMessage(&Msg); DispatchMessage(&Msg); while(timer_counter > 0) { if(soundId > 0 && soundId < (frameId -4)) { timer_counter--; break; } SendMessage(hMainWnd, MSG_TIMER, skip, 0); skip = timer_counter -1; for(i=0; i<= skip; i++) timer_counter --; } } FlashClose(flashHandle); if(xc->bmp) { if(xc->bmp->bmBits) free(xc->bmp->bmBits); free(xc->bmp); } MainWindowThreadCleanup(hMainWnd); return 0;}#ifndef _LITE_VERSION#include <minigui/dti.c>#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?