Update ooo320-m1
[ooovba.git] / slideshow / source / engine / animationnodes / animationaudionode.cxx
blobc1df04a4b41d588a00c235b78dafa8458a016f21
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: animationaudionode.cxx,v $
10 * $Revision: 1.15 $
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"
34 // must be first
35 #include <canvas/debug.hxx>
36 #include <canvas/verbosetrace.hxx>
38 #include "eventqueue.hxx"
39 #include "animationaudionode.hxx"
40 #include "delayevent.hxx"
41 #include "tools.hxx"
42 #include "nodetools.hxx"
43 #include "boost/bind.hpp"
45 using namespace com::sun::star;
47 namespace slideshow {
48 namespace internal {
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 ),
56 maSoundURL(),
57 mpPlayer()
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()
70 resetPlayer();
71 mxAudioNode.clear();
72 BaseNode::dispose();
75 void AnimationAudioNode::activate_st()
77 createPlayer();
79 AnimationEventHandlerSharedPtr aHandler(
80 boost::dynamic_pointer_cast<AnimationEventHandler>( getSelf() ) );
81 OSL_ENSURE( aHandler,
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();
92 else
94 // no node duration. Take inherent media time, then
95 scheduleDeactivationEvent(
96 makeDelay( boost::bind( &AnimationNode::deactivate, getSelf() ),
97 mpPlayer->getDuration() ) );
100 else
102 // deactivate ASAP:
103 scheduleDeactivationEvent(
104 makeEvent( boost::bind( &AnimationNode::deactivate, getSelf() ) ) );
108 // TODO(F2): generate deactivation event, when sound
109 // is over
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 );
119 // force-end sound
120 if (mpPlayer)
122 mpPlayer->stopPlayback();
123 resetPlayer();
126 // notify _after_ state change:
127 getContext().mrEventQueue.addEvent(
128 makeEvent( boost::bind( &EventMultiplexer::notifyAudioStopped,
129 boost::ref(getContext().mrEventMultiplexer),
130 getSelf() ) ) );
133 bool AnimationAudioNode::hasPendingAnimation() const
135 // force slide to use the animation framework
136 // (otherwise, a single sound on the slide would
137 // not be played).
138 return true;
141 void AnimationAudioNode::createPlayer() const
143 if (mpPlayer)
144 return;
146 try
148 mpPlayer = SoundPlayer::create( getContext().mrEventMultiplexer,
149 maSoundURL,
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
163 if (mpPlayer)
165 mpPlayer->stopPlayback();
166 mpPlayer->dispose();
167 mpPlayer.reset();
171 bool AnimationAudioNode::handleAnimationEvent(
172 const AnimationNodeSharedPtr& /*rNode*/ )
174 // TODO(F2): for now we support only STOPAUDIO events.
175 deactivate();
176 return true;
179 } // namespace internal
180 } // namespace presentation