1 /* |
|
2 * Copyright (c) 2010 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: |
|
15 * This file provides the implementation for creating and deleting a |
|
16 * an MMF based player for playing and stopping a tone playback. |
|
17 */ |
|
18 |
|
19 #include "stsplayer.h" |
|
20 |
|
21 _LIT(KDefaultFile,"z:\\data\\sounds\\digital\\clock.aac"); |
|
22 |
|
23 /*static*/CStsPlayer* CStsPlayer::CreateTonePlayer( |
|
24 MStsPlayerObserver& aObserver, CSystemToneService::TToneType aTone, |
|
25 unsigned int aContext) |
|
26 { |
|
27 CStsPlayer* self = 0; |
|
28 switch (aTone) |
|
29 { |
|
30 default: |
|
31 self = new CStsPlayer(aObserver, KDefaultFile, 0, aContext); |
|
32 break; |
|
33 } |
|
34 if (self != 0) |
|
35 { |
|
36 bool successful = self->Init(); |
|
37 if (!successful) |
|
38 { |
|
39 delete self; |
|
40 self = 0; |
|
41 } |
|
42 } |
|
43 return self; |
|
44 } |
|
45 |
|
46 /*static*/CStsPlayer* CStsPlayer::CreateAlarmPlayer( |
|
47 MStsPlayerObserver& aObserver, CSystemToneService::TAlarmType aAlarm, |
|
48 unsigned int aContext) |
|
49 { |
|
50 CStsPlayer* self = 0; |
|
51 switch (aAlarm) |
|
52 { |
|
53 case CSystemToneService::EClockAlarm: |
|
54 self = new CStsPlayer(aObserver, KDefaultFile, 10, aContext); |
|
55 break; |
|
56 default: |
|
57 self = new CStsPlayer(aObserver, KDefaultFile, 10, aContext); |
|
58 break; |
|
59 } |
|
60 if (self != 0) |
|
61 { |
|
62 bool successful = self->Init(); |
|
63 if (!successful) |
|
64 { |
|
65 delete self; |
|
66 self = 0; |
|
67 } |
|
68 } |
|
69 return self; |
|
70 } |
|
71 |
|
72 CStsPlayer::CStsPlayer(MStsPlayerObserver& aObserver, const TDesC& aFileName, |
|
73 int aRepeatNumberOfTimes, unsigned int aContext) : |
|
74 iObserver(aObserver), iPlayer(0), iFileName(aFileName), |
|
75 iRepeatNumberOfTimes(aRepeatNumberOfTimes), iContext(aContext) |
|
76 { |
|
77 } |
|
78 |
|
79 bool CStsPlayer::Init() |
|
80 { |
|
81 TRAPD(result, iPlayer = CMdaAudioPlayerUtility::NewL(*this)); |
|
82 return result == KErrNone; |
|
83 } |
|
84 |
|
85 CStsPlayer::~CStsPlayer() |
|
86 { |
|
87 delete iPlayer; |
|
88 } |
|
89 |
|
90 void CStsPlayer::Play() |
|
91 { |
|
92 // Play the tone |
|
93 TRAPD(err, iPlayer->OpenFileL(iFileName)); |
|
94 |
|
95 // If there is an error, indicate that the playback is complete. |
|
96 if (err) |
|
97 { |
|
98 //TODO: Add trace here |
|
99 iObserver.PlayComplete(iContext); |
|
100 } |
|
101 } |
|
102 |
|
103 void CStsPlayer::Stop() |
|
104 { |
|
105 iPlayer->Stop(); |
|
106 } |
|
107 |
|
108 void CStsPlayer::MapcInitComplete(TInt aError, |
|
109 const TTimeIntervalMicroSeconds& /*aDuration*/) |
|
110 { |
|
111 if (aError == KErrNone) |
|
112 { |
|
113 TTimeIntervalMicroSeconds delay = 0; |
|
114 iPlayer->SetRepeats(iRepeatNumberOfTimes, delay); |
|
115 iPlayer->Play(); |
|
116 } |
|
117 else |
|
118 { |
|
119 //TODO: add trace |
|
120 // Since there is an error, indicate that the playback is complete |
|
121 iObserver.PlayComplete(iContext); |
|
122 } |
|
123 } |
|
124 |
|
125 void CStsPlayer::MapcPlayComplete(TInt aError) |
|
126 { |
|
127 if (aError != KErrNone) |
|
128 { |
|
129 //TODO: add trace |
|
130 } |
|
131 iObserver.PlayComplete(iContext); |
|
132 } |
|