1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: animationaudionode.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_slideshow.hxx"
35 #include <canvas/debug.hxx>
36 #include <canvas/verbosetrace.hxx>
38 #include "eventqueue.hxx"
39 #include "animationaudionode.hxx"
40 #include "delayevent.hxx"
42 #include "nodetools.hxx"
43 #include "boost/bind.hpp"
45 using namespace com::sun::star
;
50 AnimationAudioNode::AnimationAudioNode(
51 const uno::Reference
< animations::XAnimationNode
>& xNode
,
52 const BaseContainerNodeSharedPtr
& rParent
,
53 const NodeContext
& rContext
)
54 : BaseNode( xNode
, rParent
, rContext
),
55 mxAudioNode( xNode
, uno::UNO_QUERY_THROW
),
59 mxAudioNode
->getSource() >>= maSoundURL
;
61 OSL_ENSURE( maSoundURL
.getLength(),
62 "could not extract sound source URL/empty URL string" );
64 ENSURE_OR_THROW( getContext().mxComponentContext
.is(),
65 "Invalid component context" );
68 void AnimationAudioNode::dispose()
75 void AnimationAudioNode::activate_st()
79 AnimationEventHandlerSharedPtr
aHandler(
80 boost::dynamic_pointer_cast
<AnimationEventHandler
>( getSelf() ) );
82 "could not cast self to AnimationEventHandler?" );
83 getContext().mrEventMultiplexer
.addCommandStopAudioHandler( aHandler
);
85 if (mpPlayer
&& mpPlayer
->startPlayback())
87 // TODO(F2): Handle end time attribute, too
88 if( getXAnimationNode()->getDuration().hasValue() )
90 scheduleDeactivationEvent();
94 // no node duration. Take inherent media time, then
95 scheduleDeactivationEvent(
96 makeDelay( boost::bind( &AnimationNode::deactivate
, getSelf() ),
97 mpPlayer
->getDuration() ) );
103 scheduleDeactivationEvent(
104 makeEvent( boost::bind( &AnimationNode::deactivate
, getSelf() ) ) );
108 // TODO(F2): generate deactivation event, when sound
111 void AnimationAudioNode::deactivate_st( NodeState
/*eDestState*/ )
113 AnimationEventHandlerSharedPtr
aHandler(
114 boost::dynamic_pointer_cast
<AnimationEventHandler
>( getSelf() ) );
115 OSL_ENSURE( aHandler
,
116 "could not cas self to AnimationEventHandler?" );
117 getContext().mrEventMultiplexer
.removeCommandStopAudioHandler( aHandler
);
122 mpPlayer
->stopPlayback();
126 // notify _after_ state change:
127 getContext().mrEventQueue
.addEvent(
128 makeEvent( boost::bind( &EventMultiplexer::notifyAudioStopped
,
129 boost::ref(getContext().mrEventMultiplexer
),
133 bool AnimationAudioNode::hasPendingAnimation() const
135 // force slide to use the animation framework
136 // (otherwise, a single sound on the slide would
141 void AnimationAudioNode::createPlayer() const
148 mpPlayer
= SoundPlayer::create( getContext().mrEventMultiplexer
,
150 getContext().mxComponentContext
);
152 catch( lang::NoSupportException
& )
154 // catch possible exceptions from SoundPlayer,
155 // since being not able to playback the sound
156 // is not a hard error here (remainder of the
157 // animations should still work).
161 void AnimationAudioNode::resetPlayer() const
165 mpPlayer
->stopPlayback();
171 bool AnimationAudioNode::handleAnimationEvent(
172 const AnimationNodeSharedPtr
& /*rNode*/ )
174 // TODO(F2): for now we support only STOPAUDIO events.
179 } // namespace internal
180 } // namespace presentation