2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/system/common/sound-player-impl.h>
22 #include <dali/devel-api/common/singleton-service.h>
23 #include <dali/public-api/object/type-registry.h>
31 namespace // unnamed namespace
33 const char* const SIGNAL_SOUND_PLAY_FINISHED = "soundPlayFinished";
36 Dali::BaseHandle GetInstance()
38 return SoundPlayer::Get();
41 Dali::TypeRegistration SOUND_PLAYER_TYPE(typeid(Dali::SoundPlayer), typeid(Dali::BaseHandle), GetInstance);
43 Dali::SignalConnectorType SIGNAL_CONNECTOR_1(SOUND_PLAYER_TYPE, SIGNAL_SOUND_PLAY_FINISHED, Dali::Internal::Adaptor::SoundPlayer::DoConnectSignal);
45 } // unnamed namespace
47 Dali::SoundPlayer SoundPlayer::New()
49 Dali::SoundPlayer player = Dali::SoundPlayer(new SoundPlayer());
53 Dali::SoundPlayer SoundPlayer::Get()
55 Dali::SoundPlayer player;
57 Dali::SingletonService service(SingletonService::Get());
60 // Check whether the singleton is already created
61 Dali::BaseHandle handle = service.GetSingleton(typeid(Dali::SoundPlayer));
64 // If so, downcast the handle
65 player = Dali::SoundPlayer(dynamic_cast<SoundPlayer*>(handle.GetObjectPtr()));
69 player = Dali::SoundPlayer(New());
70 service.Register(typeid(player), player);
77 int SoundPlayer::PlaySound(const std::string fileName)
79 return mPlugin.PlaySound(fileName);
82 void SoundPlayer::Stop(int handle)
84 mPlugin.StopSound(handle);
87 SoundPlayer::SoundPlayFinishedSignalType& SoundPlayer::SoundPlayFinishedSignal()
89 return mSoundPlayFinishedSignal;
92 bool SoundPlayer::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
95 SoundPlayer* player = dynamic_cast<SoundPlayer*>(object);
97 if(player && (SIGNAL_SOUND_PLAY_FINISHED == signalName))
99 player->SoundPlayFinishedSignal().Connect(tracker, functor);
103 // signalName does not match any signal
110 SoundPlayer::SoundPlayer()
111 : mPlugin(FeedbackPluginProxy::DEFAULT_OBJECT_NAME)
115 SoundPlayer::~SoundPlayer()
119 void SoundPlayer::EmitSoundPlayFinishedSignal()
121 // Emit SoundPlayFinished signal
123 if(!mSoundPlayFinishedSignal.Empty())
125 Dali::SoundPlayer handle(this);
126 mSoundPlayFinishedSignal.Emit(handle);
130 } // namespace Adaptor
132 } // namespace Internal