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/public-api/object/type-registry.h>
25 #include <dali/internal/system/common/singleton-service-impl.h>
36 namespace // unnamed namespace
39 const char* const SIGNAL_SOUND_PLAY_FINISHED = "soundPlayFinished";
42 Dali::BaseHandle GetInstance()
44 return SoundPlayer::Get();
47 Dali::TypeRegistration SOUND_PLAYER_TYPE( typeid(Dali::SoundPlayer), typeid(Dali::BaseHandle), GetInstance );
49 Dali::SignalConnectorType SIGNAL_CONNECTOR_1( SOUND_PLAYER_TYPE, SIGNAL_SOUND_PLAY_FINISHED, Dali::Internal::Adaptor::SoundPlayer::DoConnectSignal );
51 } // unnamed namespace
53 Dali::SoundPlayer SoundPlayer::New()
55 Dali::SoundPlayer player = Dali::SoundPlayer( new SoundPlayer() );
59 Dali::SoundPlayer SoundPlayer::Get()
61 Dali::SoundPlayer player;
63 Dali::SingletonService service( SingletonService::Get() );
66 // Check whether the singleton is already created
67 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::SoundPlayer ) );
70 // If so, downcast the handle
71 player = Dali::SoundPlayer( dynamic_cast< SoundPlayer* >( handle.GetObjectPtr() ) );
75 player = Dali::SoundPlayer( New() );
76 service.Register( typeid( player ), player );
83 int SoundPlayer::PlaySound( const std::string fileName )
85 return mPlugin.PlaySound( fileName );
88 void SoundPlayer::Stop( int handle )
90 mPlugin.StopSound( handle );
93 SoundPlayer::SoundPlayFinishedSignalType& SoundPlayer::SoundPlayFinishedSignal()
95 return mSoundPlayFinishedSignal;
98 bool SoundPlayer::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
100 bool connected( true );
101 SoundPlayer* player = dynamic_cast<SoundPlayer*>( object );
103 if( player && ( SIGNAL_SOUND_PLAY_FINISHED == signalName ) )
105 player->SoundPlayFinishedSignal().Connect( tracker, functor );
109 // signalName does not match any signal
116 SoundPlayer::SoundPlayer()
117 : mPlugin( FeedbackPluginProxy::DEFAULT_OBJECT_NAME )
121 SoundPlayer::~SoundPlayer()
125 void SoundPlayer::EmitSoundPlayFinishedSignal()
127 // Emit SoundPlayFinished signal
129 if ( !mSoundPlayFinishedSignal.Empty() )
131 Dali::SoundPlayer handle( this );
132 mSoundPlayFinishedSignal.Emit( handle );
136 } // namespace Adaptor
138 } // namespace Internal