void SSoundEntity::Resume( const char* sSoundOrEvent, float fPos ) { if ( sSoundOrEvent && *sSoundOrEvent ) { // If not empty if ( pSoundProxy ) { // Soundproxy initialized // first pause the current sound if ( nSoundID != INVALID_SOUNDID ) { pSoundProxy->PauseSound( nSoundID, false ); } pSound = nSoundID != INVALID_SOUNDID ? pSoundProxy->GetSound( nSoundID ) : NULL; if ( !IsSoundPlaying( pSound ) ) { // if the current sound is not playing anymore then open the new sound #if CDK_VERSION < 343 nSoundID = pSoundProxy->PlaySoundEx( sSoundOrEvent, vOffset, vDirection, nSoundFlags, fVolume, fMinRadius, fMaxRadius, eSemantic ); #else nSoundID = pSoundProxy->PlaySoundEx( sSoundOrEvent, vOffset, vDirection, nSoundFlags, 0, fVolume, fMinRadius, fMaxRadius, eSemantic ); #endif pSound = nSoundID != INVALID_SOUNDID ? pSoundProxy->GetSound( nSoundID ) : NULL; if ( !pSound ) { // if not successful then try again while also doing some cleanup on the proxy pSoundProxy->StopAllSounds(); pSoundProxy->UpdateSounds(); #if CDK_VERSION < 343 nSoundID = pSoundProxy->PlaySoundEx( sSoundOrEvent, vOffset, vDirection, nSoundFlags, fVolume, fMinRadius, fMaxRadius, eSemantic ); #else nSoundID = pSoundProxy->PlaySoundEx( sSoundOrEvent, vOffset, vDirection, nSoundFlags, 0, fVolume, fMinRadius, fMaxRadius, eSemantic ); #endif pSound = nSoundID != INVALID_SOUNDID ? pSoundProxy->GetSound( nSoundID ) : NULL; } if ( pSound ) { pSound->GetInterfaceExtended()->SetSoundPriority( MOVIE_SOUND_PRIORITY - 1 ); // 3D sound have lower priority then 2D #ifdef SOUNDWRAPPER_PRELOAD pSound->GetInterfaceExtended()->Preload(); #endif } } Seek( fPos ); // seek to the position requested // Resume playback if ( nSoundID != INVALID_SOUNDID ) { pSoundProxy->PauseSound( nSoundID, false ); } } } }
bool CCE3SoundWrapper::IsPlaying() { if ( IsActive() ) { // Returns true if at least one sound is playing ISound* sound = GetPreferredSound(); bool bPlaying = IsSoundPlaying( sound ); if ( !bPlaying && !m_bPaused && !m_sSoundOrEvent.empty() ) { Resume(); // restore consistency } return IsSoundPlaying( sound ); } return false; }
int FindNextFreeChannel() { for (std::vector<unsigned int>::iterator i = gChannels.begin(); i != gChannels.end(); ++i) { if(!IsSoundPlaying(*i)) // potential issue, if sound just paused! { return *i; } } return -1; }
void CCE3SoundWrapper::Resume() { if ( m_sSoundOrEvent && m_sSoundOrEvent.length() ) { // If not empty if ( m_b2DSoundActive && !m_p2DSound ) { m_p2DSound = gEnv->pSystem->GetISoundSystem()->CreateSound( m_sSoundOrEvent, m_n2DSoundFlags ); // create sound without entity proxy if ( m_p2DSound ) { m_p2DSound->SetSemantic( eSoundSemantic_HUD ); m_p2DSound->GetInterfaceExtended()->SetSoundPriority( MOVIE_SOUND_PRIORITY ); // 2d sound gets highest priority #ifdef SOUNDWRAPPER_PRELOAD m_p2DSound->GetInterfaceExtended()->Preload(); #endif } } if ( m_p2DSound && !IsSoundPlaying( m_p2DSound ) ) { RefreshMaxDuration( m_p2DSound ); m_p2DSound->Play( m_f2DVolume ); m_p2DSound->GetInterfaceExtended()->SetCurrentSamplePos( m_pSyncTimesource->GetPosition() * MILLISECOND, true ); #ifdef SOUNDWRAPPER_PRELOAD m_p2DSound->GetInterfaceExtended()->Preload(); #endif m_p2DSound->SetPaused( false ); // start playback RefreshMaxDuration( m_p2DSound ); // retrieve duration later it becomes sometimes unreliable } for ( tEntitySoundProxyMap::iterator iterSound = m_SoundProxies.begin(); iterSound != m_SoundProxies.end(); ++iterSound ) { SSoundEntity& se = iterSound->second; se.Resume( m_sSoundOrEvent, m_pSyncTimesource->GetPosition() ); RefreshMaxDuration( se.GetSound() ); } // goto position of sync target Seek( m_pSyncTimesource->GetPosition() ); m_bPaused = false; } }
TSharedPtr<SWidget> FAssetTypeActions_SoundWave::GetThumbnailOverlay(const FAssetData& AssetData) const { TArray<TWeakObjectPtr<USoundBase>> SoundList; SoundList.Add(TWeakObjectPtr<USoundBase>((USoundBase*)AssetData.GetAsset())); auto OnGetDisplayBrushLambda = [this, SoundList]() -> const FSlateBrush* { if (IsSoundPlaying(SoundList)) { return FEditorStyle::GetBrush("MediaAsset.AssetActions.Stop"); } return FEditorStyle::GetBrush("MediaAsset.AssetActions.Play"); }; auto IsEnabledLambda = [this, SoundList]() -> bool { return CanExecutePlayCommand(SoundList); }; auto OnClickedLambda = [this, SoundList]() -> FReply { if (IsSoundPlaying(SoundList)) { ExecuteStopSound(SoundList); } else { ExecutePlaySound(SoundList); } return FReply::Handled(); }; auto OnToolTipTextLambda = [this, SoundList]() -> FText { if (IsSoundPlaying(SoundList)) { return LOCTEXT("Blueprint_StopSoundToolTip", "Stop selected Sound Wave"); } return LOCTEXT("Blueprint_PlaySoundToolTip", "Play selected Sound Wave"); }; return SNew(SBox) .HAlign(HAlign_Center) .VAlign(VAlign_Center) .Padding(FMargin(2)) [ SNew(SButton) .ButtonStyle(FEditorStyle::Get(), "HoverHintOnly") .ToolTipText_Lambda(OnToolTipTextLambda) .Cursor(EMouseCursor::Default) // The outer widget can specify a DragHand cursor, so we need to override that here .ForegroundColor(FSlateColor::UseForeground()) .IsEnabled_Lambda(IsEnabledLambda) .OnClicked_Lambda(OnClickedLambda) [ SNew(SBox) .MinDesiredWidth(16) .MinDesiredHeight(16) [ SNew(SImage) .Image_Lambda(OnGetDisplayBrushLambda) ] ] ]; }