20
|
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 |
*/
|
43
|
18 |
|
|
19 |
// Include Files
|
21
|
20 |
#include "stsplayer.h"
|
|
21 |
#include <AudioPreference.h>
|
|
22 |
#include <systemtoneservice.h>
|
43
|
23 |
#include "stsplayersettings.h"
|
|
24 |
#include "stssettingsmanager.h"
|
48
|
25 |
#include "stsdebug.h"
|
21
|
26 |
|
43
|
27 |
/*static*/CStsPlayer* CStsPlayer::Create(MStsPlayerObserver& aObserver,
|
|
28 |
CStsSettingsManager& aSettingsManager, unsigned int aContext,
|
|
29 |
CSystemToneService::TAlarmType aAlarm)
|
20
|
30 |
{
|
|
31 |
CStsPlayer* self = 0;
|
43
|
32 |
CStsSettingsManager::MPlayerSettings& playerSettings =
|
|
33 |
aSettingsManager.GetPlayerSettings(aAlarm);
|
|
34 |
TUint audioPreference;
|
|
35 |
TUint audioPriority;
|
|
36 |
aSettingsManager.GetAudioPriorityPref(aAlarm, audioPriority,
|
|
37 |
audioPreference);
|
|
38 |
self = new CStsPlayer(aObserver, playerSettings, aContext,
|
|
39 |
audioPreference, audioPriority);
|
|
40 |
if (self != 0)
|
|
41 |
{
|
|
42 |
bool successful = self->Init();
|
|
43 |
if (!successful)
|
20
|
44 |
{
|
43
|
45 |
delete self;
|
|
46 |
self = 0;
|
20
|
47 |
}
|
43
|
48 |
}
|
20
|
49 |
return self;
|
|
50 |
}
|
|
51 |
|
43
|
52 |
/*static*/CStsPlayer* CStsPlayer::Create(MStsPlayerObserver& aObserver,
|
|
53 |
CStsSettingsManager& aSettingsManager, unsigned int aContext,
|
|
54 |
CSystemToneService::TToneType aTone)
|
20
|
55 |
{
|
|
56 |
CStsPlayer* self = 0;
|
43
|
57 |
CStsSettingsManager::MPlayerSettings& playerSettings =
|
|
58 |
aSettingsManager.GetPlayerSettings(aTone);
|
|
59 |
TUint audioPreference;
|
|
60 |
TUint audioPriority;
|
|
61 |
aSettingsManager.GetAudioPriorityPref(aTone, audioPriority,
|
|
62 |
audioPreference);
|
|
63 |
self = new CStsPlayer(aObserver, playerSettings, aContext,
|
|
64 |
audioPreference, audioPriority);
|
|
65 |
if (self != 0)
|
|
66 |
{
|
|
67 |
bool successful = self->Init();
|
|
68 |
if (!successful)
|
20
|
69 |
{
|
43
|
70 |
delete self;
|
|
71 |
self = 0;
|
|
72 |
}
|
|
73 |
}
|
20
|
74 |
return self;
|
|
75 |
}
|
|
76 |
|
43
|
77 |
CStsPlayer::CStsPlayer(MStsPlayerObserver& aObserver,
|
|
78 |
CStsSettingsManager::MPlayerSettings& aPlayerSettings,
|
|
79 |
unsigned int aContext, TUint aAudioPreference, TUint aAudioPriority) :
|
|
80 |
iObserver(aObserver), iPlayerSettings(aPlayerSettings),
|
|
81 |
iContext(aContext), iAudioPreference(aAudioPreference),
|
|
82 |
iAudioPriority(aAudioPriority), iPlayer(0)
|
20
|
83 |
{
|
|
84 |
}
|
|
85 |
|
|
86 |
bool CStsPlayer::Init()
|
|
87 |
{
|
43
|
88 |
TRAPD(result, iPlayer = CMdaAudioPlayerUtility::NewL(*this));
|
48
|
89 |
TRACE_LOG((_L("CStsPlayer::Init() : CMdaAudioPlayerUtility::NewL result[%d]"), result));
|
43
|
90 |
return result == KErrNone;
|
20
|
91 |
}
|
|
92 |
|
|
93 |
CStsPlayer::~CStsPlayer()
|
|
94 |
{
|
48
|
95 |
TRACE_FUNCTION_ENTRY;
|
43
|
96 |
delete iPlayer;
|
48
|
97 |
TRACE_FUNCTION_EXIT;
|
20
|
98 |
}
|
|
99 |
|
|
100 |
void CStsPlayer::Play()
|
|
101 |
{
|
|
102 |
// Play the tone
|
43
|
103 |
TRAPD( err, iPlayer->OpenFileL(iPlayerSettings.GetFileName()) );
|
48
|
104 |
TRACE_LOG((_L("CStsPlayer::Play() : CMdaAudioPlayerUtility::OpenFileL result[%d]"), err));
|
20
|
105 |
// If there is an error, indicate that the playback is complete.
|
|
106 |
if (err)
|
|
107 |
{
|
|
108 |
//TODO: Add trace here
|
|
109 |
iObserver.PlayComplete(iContext);
|
|
110 |
}
|
|
111 |
}
|
|
112 |
|
|
113 |
void CStsPlayer::Stop()
|
|
114 |
{
|
48
|
115 |
TRACE_FUNCTION_ENTRY;
|
20
|
116 |
iPlayer->Stop();
|
48
|
117 |
TRACE_FUNCTION_EXIT;
|
20
|
118 |
}
|
|
119 |
|
|
120 |
void CStsPlayer::MapcInitComplete(TInt aError,
|
|
121 |
const TTimeIntervalMicroSeconds& /*aDuration*/)
|
|
122 |
{
|
|
123 |
if (aError == KErrNone)
|
|
124 |
{
|
43
|
125 |
TInt64 volumex100 = iPlayer->MaxVolume()
|
|
126 |
* iPlayerSettings.GetVolumePercentage();
|
|
127 |
TInt volume = volumex100 / 100;
|
21
|
128 |
// Set PriorityPref
|
43
|
129 |
iPlayer->SetPriority(iAudioPriority, iAudioPreference);
|
|
130 |
iPlayer->SetRepeats(iPlayerSettings.GetNumberOfRepeats(),
|
|
131 |
iPlayerSettings.GetRepeatDelay());
|
|
132 |
iPlayer->SetVolume(volume);
|
|
133 |
iPlayer->SetVolumeRamp(iPlayerSettings.GetVolumeRamp());
|
48
|
134 |
TRACE_LOG((_L("CStsPlayer::Play() Settings-Priority[%d]Preference[0x%x]Repeats[%d]Volume[%d]"),
|
|
135 |
iAudioPriority,
|
|
136 |
iAudioPreference,
|
|
137 |
iPlayerSettings.GetNumberOfRepeats(),
|
|
138 |
volume));
|
|
139 |
TRACE_LOG((_L("CStsPlayer::Play() Settings-RepeatDelay[%d]VolumeRamp[0x%x]"),
|
|
140 |
iPlayerSettings.GetRepeatDelay().Int64(),
|
|
141 |
iPlayerSettings.GetVolumeRamp().Int64()));
|
20
|
142 |
iPlayer->Play();
|
|
143 |
}
|
|
144 |
else
|
|
145 |
{
|
|
146 |
//TODO: add trace
|
|
147 |
// Since there is an error, indicate that the playback is complete
|
48
|
148 |
//RDebug::Print(_L("InitCompleteReturned"), aError);
|
|
149 |
TRACE_LOG((_L("CStsPlayer::MapcInitComplete() Error[%d]"), aError));
|
20
|
150 |
iObserver.PlayComplete(iContext);
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
|
154 |
void CStsPlayer::MapcPlayComplete(TInt aError)
|
|
155 |
{
|
48
|
156 |
TRACE_LOG((_L("CStsPlayer::MapcPlayComplete() Error[%d]"), aError));
|
20
|
157 |
if (aError != KErrNone)
|
|
158 |
{
|
|
159 |
//TODO: add trace
|
|
160 |
}
|
|
161 |
iObserver.PlayComplete(iContext);
|
|
162 |
}
|