prism2.device: Compiler delint
[AROS.git] / workbench / c / Play.c
blobef50819e55fd07e8528777f4ce00c37d3c0e3433
1 /*
2 Copyright © 2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /******************************************************************************
11 NAME
13 Play
15 SYNOPSIS
17 FILE/S
19 LOCATION
23 FUNCTION
25 Play a sound file, using datatypes.library
27 INPUTS
29 FILE f -- Filename to play
31 RESULT
33 Sound should play to the default audio device
35 NOTES
37 EXAMPLE
39 BUGS
41 SEE ALSO
43 INTERNALS
45 HISTORY
47 ******************************************************************************/
49 #define DEBUG 0
50 #include <aros/debug.h>
52 #include <exec/memory.h>
53 #include <proto/exec.h>
54 #include <proto/dos.h>
55 #include <proto/alib.h>
56 #include <proto/datatypes.h>
58 #include <datatypes/datatypesclass.h>
59 #include <datatypes/soundclass.h>
61 #include <aros/shcommands.h>
63 static inline BOOL isPlayable(struct Library *DataTypesBase, Object *obj)
65 struct DTMethod *dtm;
67 for (dtm = GetDTTriggerMethods(obj); dtm && dtm->dtm_Label; dtm++) {
68 if (dtm->dtm_Method == STM_PLAY)
69 return TRUE;
72 return FALSE;
75 AROS_SH1H(Play , 44.0, "Play a sound file using DataTypes\n",
76 AROS_SHAH(STRPTR, ,FILE , ,NULL , "File to play\n") )
78 AROS_SHCOMMAND_INIT
80 struct Library *DataTypesBase;
81 STRPTR file = SHArg(FILE);
83 SetIoErr(RETURN_FAIL);
85 if (file != NULL) {
86 if ((DataTypesBase = OpenLibrary("datatypes.library", 0))) {
87 Object *o;
88 if ((o = NewDTObject(file, TAG_END))) {
89 if (isPlayable(DataTypesBase, o)) {
90 struct dtTrigger msg;
91 msg.MethodID = DTM_TRIGGER;
92 msg.dtt_GInfo = NULL;
93 msg.dtt_Function = STM_PLAY;
94 msg.dtt_Data = NULL;
95 if (0 == DoDTMethodA(o, NULL, NULL, (Msg)&msg)) {
96 SetIoErr(0);
97 } else {
98 Printf("Can't play \"%s\"\n", file);
99 SetIoErr(RETURN_FAIL);
101 } else {
102 Printf("\"%s\" is not a DataType playable sound file\n", file);
103 SetIoErr(RETURN_FAIL);
105 DisposeDTObject(o);
106 } else {
107 Printf("Can't open %s as a DataType object\n", file);
109 CloseLibrary(DataTypesBase);
110 } else {
111 Printf("Can't open datatypes.library\n");
113 } else {
114 /* No file supplied - quiet success */
115 SetIoErr(0);
118 return IoErr();
120 AROS_SHCOMMAND_EXIT