|
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 #include "stsplayer.h" |
|
19 _LIT(KDefaultFile,"z:\\data\\sounds\\digital\\clock.aac"); |
|
20 |
|
21 /*static*/CStsPlayer* CStsPlayer::Create(MStsPlayerObserver& aObserver, |
|
22 CSystemToneService::TToneType aToneType, unsigned int aPlayToneContext) |
|
23 { |
|
24 CStsPlayer* self = 0; |
|
25 switch (aToneType) |
|
26 { |
|
27 case CSystemToneService::EClockAlarm: |
|
28 self = new CStsPlayer(aObserver, KDefaultFile, 10, aPlayToneContext); |
|
29 break; |
|
30 default: |
|
31 self = new CStsPlayer(aObserver, KDefaultFile, 0, aPlayToneContext); |
|
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 CStsPlayer::CStsPlayer(MStsPlayerObserver& aObserver, const TDesC& aFileName, |
|
47 int aRepeatNumberOfTimes, unsigned int aPlayToneContext) : |
|
48 iObserver(aObserver), iPlayer(0), iFileName(aFileName), |
|
49 iRepeatNumberOfTimes(aRepeatNumberOfTimes), iPlayToneContext( |
|
50 aPlayToneContext) |
|
51 { |
|
52 } |
|
53 |
|
54 bool CStsPlayer::Init() |
|
55 { |
|
56 TRAPD(result, iPlayer = CMdaAudioPlayerUtility::NewL(*this)); |
|
57 return result == KErrNone; |
|
58 } |
|
59 |
|
60 CStsPlayer::~CStsPlayer() |
|
61 { |
|
62 delete iPlayer; |
|
63 } |
|
64 |
|
65 void CStsPlayer::Play() |
|
66 { |
|
67 TRAP_IGNORE(iPlayer->OpenFileL(iFileName)); |
|
68 } |
|
69 |
|
70 void CStsPlayer::Stop() |
|
71 { |
|
72 iPlayer->Stop(); |
|
73 } |
|
74 |
|
75 void CStsPlayer::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/) |
|
76 { |
|
77 if (aError == KErrNone) |
|
78 { |
|
79 TTimeIntervalMicroSeconds delay = 0; |
|
80 iPlayer->SetRepeats(iRepeatNumberOfTimes, delay); |
|
81 iPlayer->Play(); |
|
82 } |
|
83 else |
|
84 { |
|
85 //TODO: add trace |
|
86 } |
|
87 } |
|
88 |
|
89 void CStsPlayer::MapcPlayComplete(TInt aError) |
|
90 { |
|
91 if (aError != KErrNone) |
|
92 { |
|
93 //TODO: add trace |
|
94 } |
|
95 iObserver.PlayToneComplete(iPlayToneContext); |
|
96 } |