2
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB
|
|
3 |
*
|
|
4 |
* All rights reserved.
|
|
5 |
* This component and the accompanying materials are made available
|
|
6 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
7 |
* which accompanies this distribution, and is available
|
|
8 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
9 |
*
|
|
10 |
* Initial Contributors:
|
|
11 |
* EmbedDev AB - initial contribution.
|
|
12 |
*
|
|
13 |
* Contributors:
|
|
14 |
*
|
|
15 |
* Description:
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include <e32std.h>
|
|
20 |
#include "SettingsEngine.h"
|
|
21 |
#include "SoundEngine.h"
|
|
22 |
#include "PodcastModel.h"
|
|
23 |
#include "ShowInfo.h"
|
|
24 |
#include "ShowEngine.h"
|
|
25 |
|
|
26 |
CSoundEngine* CSoundEngine::NewL(CPodcastModel& aPodcastModel)
|
|
27 |
{
|
|
28 |
CSoundEngine* self = new (ELeave) CSoundEngine(aPodcastModel);
|
|
29 |
CleanupStack::PushL(self);
|
|
30 |
self->ConstructL();
|
|
31 |
CleanupStack::Pop(self);
|
|
32 |
return self;
|
|
33 |
}
|
|
34 |
|
|
35 |
CSoundEngine::~CSoundEngine()
|
|
36 |
{
|
|
37 |
iObservers.Close();
|
|
38 |
}
|
|
39 |
|
|
40 |
CSoundEngine::CSoundEngine(CPodcastModel& aPodcastModel): iPodcastModel(aPodcastModel)
|
|
41 |
{
|
|
42 |
}
|
|
43 |
|
|
44 |
void CSoundEngine::ConstructL()
|
|
45 |
{
|
|
46 |
}
|
|
47 |
|
|
48 |
EXPORT_C void CSoundEngine::AddObserver(MSoundEngineObserver* aObserver)
|
|
49 |
{
|
|
50 |
iObservers.Append(aObserver);
|
|
51 |
}
|
|
52 |
|
|
53 |
void CSoundEngine::RemoveObserver(MSoundEngineObserver* observer)
|
|
54 |
{
|
|
55 |
TInt index = iObservers.Find(observer);
|
|
56 |
|
|
57 |
if (index > KErrNotFound)
|
|
58 |
{
|
|
59 |
iObservers.Remove(index);
|
|
60 |
}
|
|
61 |
}
|
|
62 |
|
|
63 |
void CSoundEngine::OpenFileL(const TDesC& aFileName, TBool aPlayOnInit)
|
|
64 |
{
|
|
65 |
iState = ESoundEngineNotInitialized;
|
|
66 |
iMaxPos = 0;
|
|
67 |
iLastOpenedFileName= aFileName;
|
|
68 |
|
|
69 |
iPlayOnInit = aPlayOnInit;
|
|
70 |
iState = ESoundEngineOpening;
|
|
71 |
}
|
|
72 |
|
|
73 |
const TFileName& CSoundEngine::LastFileName()
|
|
74 |
{
|
|
75 |
return iLastOpenedFileName;
|
|
76 |
}
|
|
77 |
|
|
78 |
EXPORT_C TTimeIntervalMicroSeconds CSoundEngine::Position()
|
|
79 |
{
|
|
80 |
TTimeIntervalMicroSeconds pos = 0;
|
|
81 |
|
|
82 |
if(iState > ESoundEngineOpening)
|
|
83 |
{
|
|
84 |
|
|
85 |
}
|
|
86 |
|
|
87 |
// store maximum position, we need this if we get interrupted by a phone call
|
|
88 |
if (pos > iMaxPos) {
|
|
89 |
iMaxPos = pos;
|
|
90 |
}
|
|
91 |
return iMaxPos;
|
|
92 |
}
|
|
93 |
|
|
94 |
EXPORT_C void CSoundEngine::SetPosition(TUint aPos)
|
|
95 |
{
|
|
96 |
if(iState > ESoundEngineOpening)
|
|
97 |
{
|
|
98 |
TTimeIntervalMicroSeconds pos = ((TUint64)aPos)*1000000;
|
|
99 |
if(iState == ESoundEnginePlaying)
|
|
100 |
{
|
|
101 |
//iPlayer->Pause();
|
|
102 |
}
|
|
103 |
|
|
104 |
iMaxPos = pos;
|
|
105 |
//iPlayer->SetPosition(pos);
|
|
106 |
|
|
107 |
if(iState == ESoundEnginePlaying)
|
|
108 |
{
|
|
109 |
//iPlayer->Play();
|
|
110 |
}
|
|
111 |
}
|
|
112 |
}
|
|
113 |
|
|
114 |
EXPORT_C void CSoundEngine::Play()
|
|
115 |
{
|
|
116 |
if(iState > ESoundEngineOpening)
|
|
117 |
{
|
|
118 |
//iPlayer->SetPosition(iMaxPos);
|
|
119 |
//iPlayer->Play();
|
|
120 |
iState = ESoundEnginePlaying;
|
|
121 |
|
|
122 |
NotifyPlaybackStarted();
|
|
123 |
}
|
|
124 |
}
|
|
125 |
|
|
126 |
EXPORT_C void CSoundEngine::Stop(TBool aMarkPlayed)
|
|
127 |
{
|
|
128 |
if(iState > ESoundEngineOpening)
|
|
129 |
{
|
|
130 |
if (aMarkPlayed) {
|
|
131 |
// seem to need to do this here, even though we do it in MapcPlayComplete
|
|
132 |
iPodcastModel.PlayingPodcast()->SetPlayState(EPlayed);
|
|
133 |
}
|
|
134 |
iState = ESoundEngineStopped;
|
|
135 |
SetPosition(0);
|
|
136 |
//iPlayer->Stop();
|
|
137 |
//iPlayer->Close();
|
|
138 |
iMaxPos = 0;
|
|
139 |
|
|
140 |
NotifyPlaybackStopped();
|
|
141 |
}
|
|
142 |
}
|
|
143 |
|
|
144 |
EXPORT_C void CSoundEngine::Pause(TBool aOverrideState)
|
|
145 |
{
|
|
146 |
DP("Pause");
|
|
147 |
if(iState > ESoundEngineOpening || aOverrideState)
|
|
148 |
{
|
|
149 |
iState = ESoundEnginePaused;
|
|
150 |
//iPlayer->Pause();
|
|
151 |
|
|
152 |
// had a crash here, so we check for NULL first
|
|
153 |
if (iPodcastModel.PlayingPodcast() != NULL) {
|
|
154 |
iPodcastModel.PlayingPodcast()->SetPosition(iMaxPos);
|
|
155 |
}
|
|
156 |
}
|
|
157 |
}
|
|
158 |
|
|
159 |
EXPORT_C TSoundEngineState CSoundEngine::State()
|
|
160 |
{
|
|
161 |
return iState;
|
|
162 |
}
|
|
163 |
|
|
164 |
void CSoundEngine::NotifyPlaybackStopped()
|
|
165 |
{
|
|
166 |
for (int i=0;i<iObservers.Count();i++) {
|
|
167 |
TRAPD(err, iObservers[i]->PlaybackStoppedL());
|
|
168 |
}
|
|
169 |
|
|
170 |
}
|
|
171 |
|
|
172 |
|
|
173 |
void CSoundEngine::NotifyPlaybackStarted()
|
|
174 |
{
|
|
175 |
for (int i=0;i<iObservers.Count();i++) {
|
|
176 |
TRAPD(err, iObservers[i]->PlaybackStartedL());
|
|
177 |
}
|
|
178 |
|
|
179 |
}
|
|
180 |
|
|
181 |
void CSoundEngine::NotifyPlaybackInitialized()
|
|
182 |
{
|
|
183 |
for (int i=0;i<iObservers.Count();i++) {
|
|
184 |
TRAPD(err, iObservers[i]->PlaybackInitializedL());
|
|
185 |
}
|
|
186 |
}
|
|
187 |
|
|
188 |
void CSoundEngine::NotifyVolumeChanged()
|
|
189 |
{
|
|
190 |
TInt max = 0;//iPlayer->MaxVolume();
|
|
191 |
|
|
192 |
TInt vol = 0;
|
|
193 |
//iPlayer->GetVolume(vol);
|
|
194 |
|
|
195 |
DP2("NotifyVolumeChanged, vol=%d, max=%d", vol, max);
|
|
196 |
for (int i=0;i<iObservers.Count();i++) {
|
|
197 |
TRAPD(err, iObservers[i]->VolumeChanged(vol, max));
|
|
198 |
}
|
|
199 |
|
|
200 |
}
|