source: trunk/classes/mm-progs/videoplayer/vioplayer.c@ 144

Last change on this file since 144 was 142, checked in by gyoung, 19 months ago

Fix warnings and error found by C++Check

File size: 7.1 KB
Line 
1#define INCL_DOS
2#define INCL_DOSFILEMGR
3#define INCL_DOSERRORS
4#define INCL_WIN
5#define INCL_WINWORKPLACE
6#define INCL_OS2MM
7#define INCL_MMIOOS2
8#define INCL_MCIOS2
9#define INCL_GPI
10#define INCL_PM
11
12#ifdef __EMX__
13//#define USE_OS2_TOOLKIT_HEADERS
14#endif
15#include <os2.h>
16#include <sys\types.h>
17#include <sys\stat.h>
18#include <stdio.h>
19#include <string.h>
20#include <stdlib.h>
21#include <os2me.h>
22#include "common.h"
23#include "mmplayerres.h"
24#include "mmres.h"
25#include "mmplayer.h"
26#include "mmprogs_defaults.h"
27#include "sys_funcs.h"
28
29
30/* Track to play. Full path */
31char chrSourceName[CCHMAXPATH]={0};
32
33BOOL bPaused=FALSE;
34ULONG ulPid;
35BOOL bIsPlaying=FALSE;
36ULONG ulPos=0;
37ULONG ulTotalLength;
38
39BOOL pauseAudioFile(HWND hwndFrame)
40{
41 int iWavePriv;
42 char chrCommand[50];
43 char retMsg[100];
44 ULONG rc;
45
46 iWavePriv=ulPid;
47
48 if(bPaused) {
49 sprintf(chrCommand,"RESUME wave%d wait", iWavePriv);
50 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
51 bPaused=FALSE;
52 // showPlayTimeDisplay( hwndFrame, TRUE);
53 }
54 else {
55 sprintf(chrCommand,"PAUSE wave%d wait", iWavePriv);
56 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
57 bPaused=TRUE;
58 }
59 return TRUE;
60}
61
62BOOL stopAudioFile(HWND hwndFrame)
63{
64 int iWavePriv;
65 char chrCommand[50];
66 char retMsg[100];
67 ULONG rc;
68
69 iWavePriv=ulPid;
70
71 if(bIsPlaying) {
72 sprintf(chrCommand,"stop wave%d wait", iWavePriv);
73 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
74
75 sprintf(chrCommand,"close wave%d wait", iWavePriv);
76 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
77
78 // _resetDisplay(hwndFrame);
79 // showPlayTimeDisplay( hwndFrame, TRUE);
80 WinStopTimer(WinQueryAnchorBlock(hwndFrame), hwndFrame, IDTIMER_PLAY);
81 bIsPlaying=FALSE;
82 bPaused=FALSE;
83 }
84 return TRUE;
85}
86
87ULONG playAudioFile(HWND hwndFrame)
88{
89 char chrCommand[CCHMAXPATH*2];
90 char chrDevice[30];
91 char retMsg[20];
92 ULONG rc;
93 int iWavePriv;
94 int iTime2=0;
95 HWND hwndNotify;
96
97
98 if(bPaused)
99 {
100 pauseAudioFile(hwndFrame);
101 return 1;
102 }
103
104 iWavePriv=++ulPid;
105 ulPos=0;
106
107 stopAudioFile(hwndFrame);
108
109
110#if 0
111 if(!getMessage(chrCommand, IDSTR_STARTINGTRACK, sizeof(chrCommand), queryResModuleHandle(), hwndFrame))
112#endif
113 sprintf(chrCommand, "Starting track...");
114 // setPlayTimeText2(hwndFrame, chrCommand);
115
116#if 0
117 if(bIsMidi)
118 strncpy(chrDevice,"SEQUENCER", sizeof(chrDevice));
119 else
120 strncpy(chrDevice,"WAVEAUDIO", sizeof(chrDevice));
121#endif
122 strncpy(chrDevice,"DIGITALVIDEO02", sizeof(chrDevice));
123 // strncpy(chrDevice,"xine", sizeof(chrDevice));
124
125 hwndNotify=hwndFrame;//WinWindowFromID(hwndTop, IDDLG_TOPMIDDLE);
126
127
128
129 /* Start audio file */
130 // sprintf(chrCommand,"open \"%s\" type %s PARENT %lx alias wave%d SHAREABLE wait",
131 // chrSourceName, chrDevice, hwndVideo, iWavePriv);
132 SysWriteToTrapLog("Here %s\n %s\n", chrSourceName, chrCommand);
133
134 sprintf(chrCommand,"open digitalvideo01 alias wave%d wait", iWavePriv);
135 // sprintf(chrCommand,"open \"%s\" alias wave%d SHAREABLE wait", chrSourceName, iWavePriv);
136 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), hwndNotify, 0);
137
138 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
139 SysWriteToTrapLog("Open error %d!\n", (rc & 0x0000ffff));
140 DosBeep(5000, 400);
141 return 0;
142 }
143
144
145#if 0
146 sprintf(chrCommand,"open %s alias wave%d SHAREABLE wait",
147 chrDevice, iWavePriv);
148 sprintf(chrCommand,"open %s alias wave%d SHAREABLE wait",
149 "digitalvideo", iWavePriv);
150 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
151 SysWriteToTrapLog("Open error %d!\n", (rc & 0x0000ffff));
152 DosBeep(5000, 400);
153 return 0;
154 }
155
156 sprintf(chrCommand,"window %s HANDLE %ld wait",
157 chrDevice, hwndVideo);
158 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
159 SysWriteToTrapLog("window error %d!\n", (rc & 0x0000ffff));
160 DosBeep(3000, 400);
161 return 0;
162 }
163 sprintf(chrCommand,"LOAD %s %s wait",
164 chrDevice, chrSourceName);
165 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
166 SysWriteToTrapLog("window error %d!\n", (rc & 0x0000ffff));
167 DosBeep(3000, 400);
168 return 0;
169 }
170#endif
171
172 /* Set time format */
173 sprintf(chrCommand,"SET wave%d TIME FORMAT MILLISECONDS wait", iWavePriv);
174 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
175 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
176 sprintf(chrCommand,"close wave%d wait",iWavePriv);
177 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
178 return 0;
179 }
180
181#if 0
182 sprintf(chrCommand,"SETPOSITIONADVISE wave%d ON EVERY 1000 notify", iWavePriv);
183 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg),hwndNotify, 0);
184 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
185 sprintf(chrCommand,"close wave%d wait",iWavePriv);
186 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
187 return 0;
188 }
189#endif
190
191 /* Get wave length in ms */
192 sprintf(chrCommand,"STATUS wave%d LENGTH WAIT", iWavePriv);
193 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
194 if((rc & 0x0000ffff)==MCIERR_SUCCESS) {
195 iTime2=atoi(retMsg);
196 sprintf(chrCommand,"%d:%02d %d:%02d -%d:%02d",iTime2/1000/60,(iTime2/1000)%60,
197 0, 0,
198 iTime2/1000/60,(iTime2/1000)%60);
199 }
200 ulTotalLength=iTime2;
201
202#if 0
203 /* Set volume */
204 sprintf(chrCommand,"SET wave%d AUDIO VOLUME %ld wait", iWavePriv, 70);
205 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
206 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
207 sprintf(chrCommand,"close wave%d",iWavePriv);
208 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
209 return 0;
210 }
211#endif
212
213 sprintf(chrCommand,"play wave%d FROM 0", iWavePriv);
214 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
215 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
216 sprintf(chrCommand,"close wave%d",iWavePriv);
217 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
218 return 0;
219 }
220 WinStartTimer(WinQueryAnchorBlock(hwndFrame), hwndFrame, IDTIMER_PLAY, PLAYTIMER_DELAY);
221
222 bIsPlaying=TRUE;
223 return 1;
224}
225
226int main(int argc, char *argv[])
227{
228 PTIB ptib;
229 PPIB ppib;
230
231 /* Save source name */
232 if(argc==2)
233 strncpy(chrSourceName, argv[1], CCHMAXPATH);
234 printf("File: %s\n", chrSourceName);
235
236 if(DosGetInfoBlocks(&ptib, &ppib)==NO_ERROR)
237 {
238 HAB hab;
239 HMQ hmq;
240
241
242 printf("Got info block...\n");
243 ulPid=ppib->pib_ulpid;
244 ppib->pib_ultype=3; /* Morph into PM */
245 if((hab=WinInitialize(0))==NULLHANDLE)
246 {
247 printf("Can't get hab.\n");
248 return -1;
249 }
250 hmq=WinCreateMsgQueue(hab,0);
251 if(!hmq) {
252 printf("Can't get hmq.\n");
253 }
254 /* WinCreateWindow(HWND_DESKTOP, WC_BUTTON, "Test", WS_VISIBLE, 0, 0, 100, 100,
255 HWND_DESKTOP, HWND_TOP, 1234, NULLHANDLE, NULLHANDLE);*/
256
257 playAudioFile(HWND_DESKTOP);
258 printf("!!!!!!!!!!!!!!! Here! %s\n", "!!!!!!!!!!!!");
259DosSleep(5000);
260 WinDestroyMsgQueue(hmq);
261 WinTerminate(hab);
262 }
263 return 0;
264
265}
Note: See TracBrowser for help on using the repository browser.