source: trunk/classes/mm-progs/videoplayer/playaudio.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: 9.8 KB
Line 
1/*
2 * mmplayer.c (C) Chris Wohlgemuth 2002-2003
3 *
4 */
5/*
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20/*
21 * If you need another license for your project/product (commercial,
22 * noncommercial, whatever) contact me at
23 *
24 * http://www.os2world.com/cdwriting
25 * http://www.geocities.com/SiliconValley/Sector/5785/
26 *
27 */
28
29#define INCL_DOS
30#define INCL_DOSFILEMGR
31#define INCL_DOSERRORS
32#define INCL_WIN
33#define INCL_OS2MM
34#define INCL_MMIOOS2
35#define INCL_MCIOS2
36#define INCL_GPI
37#define INCL_PM
38
39#include <os2.h>
40//#include "except_2.h"
41#include <sys\types.h>
42#include <sys\stat.h>
43#include <stdio.h>
44#include <string.h>
45#include <stdlib.h>
46#include "os2me.h"
47
48#include "common.h"
49
50#include "mmplayerres.h"
51#include "mmplayer.h"
52#include "sys_funcs.h"
53
54
55
56/* The object window controling the trac playing */
57HWND hwndPlayObject;
58extern PID ulPid;
59/* TRUE when track is playing */
60extern BOOL bIsPlaying;
61/* TRUE when track is paused */
62extern BOOL bPaused;
63/* Current time in track */
64extern ULONG ulPos;
65extern ULONG ulTotalLength;
66extern BOOL bIsMidi;
67extern ULONG ulVolume;
68
69extern char chrSourceName[CCHMAXPATH];
70
71extern HWND hwndVideo, hwndVideoClient;
72
73void showPlayTimeDisplay(HWND hwndFrame, BOOL bShow);
74void _resetDisplay(HWND hwndFrame);
75void setPlayTimeText2( HWND hwndDialog, char * theText);
76
77BOOL pauseAudioFile(HWND hwndFrame)
78{
79 int iWavePriv;
80 char chrCommand[50];
81 char retMsg[100];
82 ULONG rc;
83
84 iWavePriv=ulPid;
85
86 if(bPaused) {
87 sprintf(chrCommand,"RESUME wave%d wait", iWavePriv);
88 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
89 bPaused=FALSE;
90 showPlayTimeDisplay( hwndFrame, TRUE);
91 }
92 else {
93 sprintf(chrCommand,"PAUSE wave%d wait", iWavePriv);
94 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
95 bPaused=TRUE;
96 }
97 return TRUE;
98}
99
100BOOL stopAudioFile(HWND hwndFrame)
101{
102 int iWavePriv;
103 char chrCommand[50];
104 char retMsg[100];
105 ULONG rc;
106
107 iWavePriv=ulPid;
108
109 if(bIsPlaying) {
110 sprintf(chrCommand,"stop wave%d wait", iWavePriv);
111 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
112
113 sprintf(chrCommand,"close wave%d wait", iWavePriv);
114 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
115
116 _resetDisplay(hwndFrame);
117 showPlayTimeDisplay( hwndFrame, TRUE);
118 WinStopTimer(WinQueryAnchorBlock(hwndFrame), hwndFrame, IDTIMER_PLAY);
119 bIsPlaying=FALSE;
120 bPaused=FALSE;
121 }
122 return TRUE;
123}
124
125ULONG playAudioFile(HWND hwndFrame)
126{
127 char chrCommand[CCHMAXPATH*2];
128 char chrDevice[30];
129 char retMsg[20];
130 ULONG rc;
131 int iWavePriv;
132 int iTime2 = 0;
133 HWND hwndNotify;
134
135
136 if(bPaused)
137 {
138 pauseAudioFile(hwndFrame);
139 return 1;
140 }
141
142 iWavePriv=++ulPid;
143 ulPos=0;
144
145 stopAudioFile(hwndFrame);
146
147
148#if 0
149 if(!getMessage(chrCommand, IDSTR_STARTINGTRACK, sizeof(chrCommand), queryResModuleHandle(), hwndFrame))
150#endif
151 sprintf(chrCommand, "Starting track...");
152 setPlayTimeText2(hwndFrame, chrCommand);
153
154#if 0
155 if(bIsMidi)
156 strncpy(chrDevice,"SEQUENCER", sizeof(chrDevice));
157 else
158 strncpy(chrDevice,"WAVEAUDIO", sizeof(chrDevice));
159#endif
160 strncpy(chrDevice,"DIGITALVIDEO02", sizeof(chrDevice) - 1);
161 // strncpy(chrDevice,"xine", sizeof(chrDevice));
162 hwndNotify=hwndFrame;//WinWindowFromID(hwndTop, IDDLG_TOPMIDDLE);
163
164
165
166 /* Start audio file */
167 sprintf(chrCommand,"open \"%s\" type %s PARENT %lx alias wave%d SHAREABLE wait",
168 chrSourceName, chrDevice, hwndVideo, iWavePriv);
169
170 sprintf(chrCommand,"open \"%s\" type %s alias wave%d SHAREABLE wait",
171 chrSourceName, chrDevice, iWavePriv);
172
173 SysWriteToTrapLog("Here %s\n %s\n", chrSourceName, chrCommand);
174
175 // sprintf(chrCommand,"open digitalvideo01 alias vid wait", chrSourceName, iWavePriv);
176 // sprintf(chrCommand,"open \"%s\" alias wave%d SHAREABLE wait", chrSourceName, iWavePriv);
177 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), hwndNotify, 0);
178
179 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
180 SysWriteToTrapLog("Open error %d!\n", (rc & 0x0000ffff));
181 DosBeep(5000, 400);
182 return 0;
183 }
184
185 printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
186
187#if 0
188 sprintf(chrCommand,"open %s alias wave%d SHAREABLE wait",
189 chrDevice, iWavePriv);
190 sprintf(chrCommand,"open %s alias wave%d SHAREABLE wait",
191 "digitalvideo", iWavePriv);
192 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
193 SysWriteToTrapLog("Open error %d!\n", (rc & 0x0000ffff));
194 DosBeep(5000, 400);
195 return 0;
196 }
197
198 sprintf(chrCommand,"window %s HANDLE %ld wait",
199 chrDevice, hwndVideo);
200 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
201 SysWriteToTrapLog("window error %d!\n", (rc & 0x0000ffff));
202 DosBeep(3000, 400);
203 return 0;
204 }
205 sprintf(chrCommand,"LOAD %s %s wait",
206 chrDevice, chrSourceName);
207 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
208 SysWriteToTrapLog("window error %d!\n", (rc & 0x0000ffff));
209 DosBeep(3000, 400);
210 return 0;
211 }
212#endif
213
214SysWriteToTrapLog("Here! %s\n", chrCommand);
215
216
217
218
219#if 0
220 /* Set time format */
221 sprintf(chrCommand,"SET wave%d TIME FORMAT MILLISECONDS wait", iWavePriv);
222 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
223 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
224 sprintf(chrCommand,"close wave%d wait",iWavePriv);
225 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
226 return 0;
227 }
228#endif
229
230#if 0
231 sprintf(chrCommand,"SETPOSITIONADVISE wave%d ON EVERY 1000 notify", iWavePriv);
232 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg),hwndNotify, 0);
233 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
234 sprintf(chrCommand,"close wave%d wait",iWavePriv);
235 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
236 return 0;
237 }
238#endif
239
240 /* Get wave length in ms */
241 sprintf(chrCommand,"STATUS wave%d LENGTH WAIT", iWavePriv);
242 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
243 if((rc & 0x0000ffff)==MCIERR_SUCCESS) {
244 iTime2=atoi(retMsg);
245 sprintf(chrCommand,"%d:%02d %d:%02d -%d:%02d",iTime2/1000/60,(iTime2/1000)%60,
246 0, 0,
247 iTime2/1000/60,(iTime2/1000)%60);
248 }
249 ulTotalLength=iTime2;
250
251#if 0
252 /* Set volume */
253 sprintf(chrCommand,"SET wave%d AUDIO VOLUME %ld wait", iWavePriv, ulVolume);
254 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
255 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
256 sprintf(chrCommand,"close wave%d",iWavePriv);
257 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
258 return 0;
259 }
260#endif
261
262 sprintf(chrCommand,"play wave%d FROM 0", iWavePriv);
263 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
264 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
265 sprintf(chrCommand,"close wave%d",iWavePriv);
266 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
267 return 0;
268 }
269
270 WinStartTimer(WinQueryAnchorBlock(hwndFrame), hwndFrame, IDTIMER_PLAY, PLAYTIMER_DELAY);
271
272 bIsPlaying=TRUE;
273 return 1;
274}
275
276BOOL seekAudioFile(LONG lPosSec)
277{
278 char chrCommand[50];
279 char retMsg[20];
280 APIRET rc;
281
282 sprintf(chrCommand,"PLAY wave%ld from %ld", ulPid, lPosSec);
283 rc=mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
284 // ulStartPosition=lPosSec;
285 bPaused=FALSE;
286
287 return TRUE;
288}
289
290void controlPlaying(HWND hwndDialog, ULONG ulAction, ULONG ulReserved)
291{
292 HWND hwndFrame=hwndDialog;
293 switch(ulAction)
294 {
295 case PLAY_FIRST:
296 playAudioFile(hwndFrame);
297 break;
298 case STOP_TRACK:
299 stopAudioFile(hwndFrame);
300 break;
301 case PAUSE_TRACK:
302 pauseAudioFile(hwndFrame);
303 break;
304 default:
305 break;
306 }
307 // WinPostMsg(hwndPlayObject, WM_APPTERMINATENOTIFY, MPFROMP(hwndDialog), MPFROMLONG(ulAction));
308}
309
310MRESULT EXPENTRY playObjectProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
311{
312 switch (msg)
313 {
314 case WM_APPTERMINATENOTIFY:
315 {
316 HWND hwndFrame=HWNDFROMMP(mp1);
317
318 switch(LONGFROMMP(mp2))
319 {
320 case PLAY_FIRST:
321 playAudioFile(hwndFrame);
322 break;
323 case STOP_TRACK:
324 stopAudioFile(hwndFrame);
325 break;
326 case PAUSE_TRACK:
327 pauseAudioFile(hwndFrame);
328 break;
329 default:
330 break;
331 }
332 return (MRESULT)0;
333 }
334 case WM_CLOSE:
335
336 break;
337 default:
338 break;
339 }
340 return WinDefWindowProc( hwnd, msg, mp1, mp2);
341}
342
343/* Every folder has one running play thread to handle play commands */
344void _Optlink playThreadFunc (void *arg)
345{
346 HAB hab;
347 HMQ hmq;
348 QMSG qmsg;
349
350 hab=WinInitialize(0);
351 if(hab) {
352 hmq=WinCreateMsgQueue(hab,0);
353 if(hmq) {
354
355 hwndPlayObject=WinCreateWindow(HWND_OBJECT,WC_STATIC,"MFObj",0,0,0,100,100,NULLHANDLE,HWND_BOTTOM,13343,NULL,NULL);
356 if(hwndPlayObject) {
357 WinSubclassWindow(hwndPlayObject,&playObjectProc);
358 /* Window created. */
359 while(WinGetMsg(hab,&qmsg,(HWND)NULL,0,0))
360 WinDispatchMsg(hab,&qmsg);
361
362 WinDestroyWindow(hwndPlayObject);
363 }
364 WinDestroyMsgQueue(hmq);
365 }
366 WinTerminate(hab);
367 }
368}
Note: See TracBrowser for help on using the repository browser.