|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This class launchs music player, then send play command |
|
15 * to the player at 2 seconds timeout. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <apacmdln.h> |
|
22 #include <apgcli.h> |
|
23 #include <e32property.h> |
|
24 #include <remconcoreapitarget.h> |
|
25 #include "btrccplayerstarter.h" |
|
26 #include "btaudioremconpskeys.h" |
|
27 #include "debug.h" |
|
28 |
|
29 // MODULE DATA STRUCTURES |
|
30 |
|
31 // mpx playeris name is mpx.exe in 5.0. |
|
32 // it is musicplayer.exe in 3.2. |
|
33 _LIT(KMpxPlayerExeName, "mpx.exe"); |
|
34 |
|
35 _LIT(KMpxPlayerSearchPatternBySID, "*102072c3*"); |
|
36 |
|
37 static const TInt KPlayCmdToPlayerDelay = 6000000; // value will be tuned later |
|
38 |
|
39 // ================= MEMBER FUNCTIONS ======================= |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CPlayerStarter::NewL |
|
43 // Two-phased constructor. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CPlayerStarter* CPlayerStarter::NewL() |
|
47 { |
|
48 CPlayerStarter* self = new (ELeave) CPlayerStarter(); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 void CPlayerStarter::SetCoreTarget(CRemConCoreApiTarget& aTarget) |
|
56 { |
|
57 iCoreTarget = &aTarget; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CPlayerStarter::CPlayerStarter |
|
62 // C++ constructor. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CPlayerStarter::CPlayerStarter() |
|
66 :CActive(EPriorityNormal) |
|
67 { |
|
68 CActiveScheduler::Add(this); |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CPlayerStarter::ConstructL |
|
73 // Symbian 2nd phase constructor. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CPlayerStarter::ConstructL() |
|
77 { |
|
78 TRACE_FUNC |
|
79 iTimer.CreateLocal(); |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // Destructor. |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 CPlayerStarter::~CPlayerStarter() |
|
87 { |
|
88 TRACE_FUNC |
|
89 // Starting player is not finished yet, send play command. Just wish the player |
|
90 // can receive it. |
|
91 if (IsActive() && iState != ERespondPlayNok) |
|
92 { |
|
93 RProperty::Set(KBTAudioRemCon, KBTAudioPlayerControl, |
|
94 EBTAudioResumePlayer); |
|
95 } |
|
96 Cancel(); |
|
97 iTimer.Close(); |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CPlayerStarter::RunL |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CPlayerStarter::RunL() |
|
105 { |
|
106 TRACE_INFO((_L("CPlayerStarter::RunL() state %d, status %d"), iState, iStatus.Int())); |
|
107 if (iStatus != KErrNone) |
|
108 { |
|
109 iState = EIdle; |
|
110 return; |
|
111 } |
|
112 switch (iState) |
|
113 { |
|
114 case ERespondPlayOk: |
|
115 { |
|
116 // Response OK has been sent to the remote device, start timer waiting |
|
117 // for player's initialization. |
|
118 iTimer.After(iStatus, KPlayCmdToPlayerDelay); |
|
119 SetActive(); |
|
120 iState = EPlayMusicTiming; |
|
121 TRACE_INFO(_L("schedule PLAY command ...")); |
|
122 break; |
|
123 } |
|
124 case EPlayMusicTiming: |
|
125 { |
|
126 // Player should have fully up and running. Send PLAY command to it |
|
127 // through our internal Play API. |
|
128 RProperty::Set(KBTAudioRemCon, KBTAudioPlayerControl, |
|
129 EBTAudioResumePlayer); |
|
130 TRACE_INFO(_L("PLAY command sent to btmonobearer")); |
|
131 iState = EIdle; |
|
132 break; |
|
133 } |
|
134 default: |
|
135 { |
|
136 iState = EIdle; |
|
137 break; |
|
138 } |
|
139 } |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CPlayerStarter::RunError |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TInt CPlayerStarter::RunError(TInt aError) |
|
147 { |
|
148 TRACE_FUNC |
|
149 (void) aError; |
|
150 return KErrNone; |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CPlayerStarter::DoCancel |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void CPlayerStarter::DoCancel() |
|
158 { |
|
159 TRACE_FUNC |
|
160 switch (iState) |
|
161 { |
|
162 case ERespondPlayOk: |
|
163 case ERespondPlayNok: |
|
164 { |
|
165 // This cancel won't cancel the response sending to the remote |
|
166 // device. (RemCon FW's cancel mechanism is only completing client's request. |
|
167 // the real operation in its server side won't be stopped.) |
|
168 iCoreTarget->Cancel(); |
|
169 break; |
|
170 } |
|
171 case EPlayMusicTiming: |
|
172 { |
|
173 iTimer.Cancel(); |
|
174 break; |
|
175 } |
|
176 } |
|
177 } |
|
178 // --------------------------------------------------------------------------- |
|
179 // A 'play' command has been received. |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 void CPlayerStarter::MrccatoPlay( |
|
183 TRemConCoreApiPlaybackSpeed /* aSpeed */, |
|
184 TRemConCoreApiButtonAction aButtonAct ) |
|
185 { |
|
186 TRACE_FUNC |
|
187 if ( ( aButtonAct == ERemConCoreApiButtonClick ) || |
|
188 ( aButtonAct == ERemConCoreApiButtonPress ) ) |
|
189 { |
|
190 StartPlayIfNeeded(); |
|
191 } |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // A command has been received. |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 void CPlayerStarter::MrccatoCommand( |
|
199 TRemConCoreApiOperationId aOperationId, |
|
200 TRemConCoreApiButtonAction aButtonAct ) |
|
201 { |
|
202 TRACE_INFO((_L("CPlayerStarter::MrccatoCommand opId %d, button %d"), |
|
203 aOperationId, aButtonAct)); |
|
204 switch (aOperationId) |
|
205 { |
|
206 case ERemConCoreApiPlay: |
|
207 { |
|
208 if ( ( aButtonAct == ERemConCoreApiButtonClick ) || |
|
209 ( aButtonAct == ERemConCoreApiButtonPress ) ) |
|
210 { |
|
211 StartPlayIfNeeded(); |
|
212 } |
|
213 break; |
|
214 } |
|
215 case ERemConCoreApiStop: |
|
216 case ERemConCoreApiPause: |
|
217 { |
|
218 if ( ( aButtonAct == ERemConCoreApiButtonClick ) || |
|
219 ( aButtonAct == ERemConCoreApiButtonPress ) ) |
|
220 { |
|
221 // if starting player is ongoing, possibly PLAY command has been scheduled |
|
222 // need to abort it. |
|
223 Cancel(); |
|
224 } |
|
225 break; |
|
226 } |
|
227 default: |
|
228 { |
|
229 break; |
|
230 } |
|
231 } |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CPlayerStarter::StartPlayIfNeeded |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 void CPlayerStarter::StartPlayIfNeeded() |
|
239 { |
|
240 TRACE_FUNC |
|
241 // unfinished business ongoing, eat the event. |
|
242 if (IsActive()) |
|
243 { |
|
244 return; |
|
245 } |
|
246 if (!IsMusicPlayerRunning()) |
|
247 { |
|
248 TRAPD(err, LaunchMusicPlayerL()); |
|
249 // Send the response of play command to remote device |
|
250 iCoreTarget->PlayResponse(iStatus, err); |
|
251 SetActive(); |
|
252 iState = (err) ? ERespondPlayNok : ERespondPlayOk; |
|
253 } |
|
254 } |
|
255 |
|
256 TBool CPlayerStarter::IsMusicPlayerRunning() |
|
257 { |
|
258 TRACE_FUNC |
|
259 // Music player is running if we can find a thread whose name contains |
|
260 // S60 Music Player's SID. |
|
261 TFindThread findt(KMpxPlayerSearchPatternBySID); |
|
262 TFullName result; |
|
263 TBool running(EFalse); |
|
264 if (!findt.Next(result)) |
|
265 { |
|
266 TRACE_INFO((_L("Thread '%S'is found"), &result)); |
|
267 running = ETrue; |
|
268 } |
|
269 return running; |
|
270 } |
|
271 |
|
272 void CPlayerStarter::LaunchMusicPlayerL() |
|
273 { |
|
274 RApaLsSession ls; |
|
275 User::LeaveIfError(ls.Connect()); |
|
276 CleanupClosePushL(ls); |
|
277 CApaCommandLine* cmd = CApaCommandLine::NewL(); |
|
278 CleanupStack::PushL(cmd); |
|
279 cmd->SetExecutableNameL( KMpxPlayerExeName ); |
|
280 cmd->SetCommandL( EApaCommandOpen ); |
|
281 User::LeaveIfError(ls.StartApp( *cmd )); |
|
282 CleanupStack::PopAndDestroy(2); // cmd, ls |
|
283 } |
|
284 |
|
285 |
|
286 // End of File |