@@ -39,6 +39,7 @@ class SpatialAudioMain: BaseViewController {
3939 @IBOutlet weak var remoteUserButton1 : UIButton !
4040 @IBOutlet weak var remoteUserButton2 : UIButton !
4141
42+ private var isJoined : Bool = false
4243 private lazy var actionView1 = SpatialAudioActionSheet ( )
4344 private lazy var actionView2 = SpatialAudioActionSheet ( )
4445 var agoraKit : AgoraRtcEngineKit !
@@ -80,13 +81,13 @@ class SpatialAudioMain: BaseViewController {
8081
8182 override func viewDidAppear( _ animated: Bool ) {
8283 super. viewDidAppear ( animated)
84+ guard isJoined == false else { return }
8385 mediaPlayer1 = agoraKit. createMediaPlayer ( with: self )
8486 mediaPlayer1. setLoopCount ( 10000 )
8587 mediaPlayer1. open ( " https://webdemo.agora.io/audiomixing.mp3 " , startPos: 0 )
8688 localSpatial. updatePlayerPositionInfo ( Int ( mediaPlayer1. getMediaPlayerId ( ) ) , positionInfo: getPlayerPostion ( view: voiceButton1) )
8789 localSpatial. setPlayerAttenuation ( 0.2 , playerId: UInt ( mediaPlayer1. getMediaPlayerId ( ) ) , forceSet: false )
8890
89-
9091 mediaPlayer2 = agoraKit. createMediaPlayer ( with: self )
9192 mediaPlayer2. setLoopCount ( 10000 )
9293 mediaPlayer2. open ( " https://webdemo.agora.io/dang.mp3 " , startPos: 0 )
@@ -103,6 +104,7 @@ class SpatialAudioMain: BaseViewController {
103104 agoraKit = nil
104105 AgoraLocalSpatialAudioKit . destroy ( )
105106 AgoraRtcEngineKit . destroy ( )
107+ isJoined = false
106108 }
107109
108110 private func joinChannel( ) {
@@ -115,6 +117,7 @@ class SpatialAudioMain: BaseViewController {
115117 if result != 0 {
116118 print ( " join channel fail " )
117119 }
120+ self . isJoined = true
118121 } )
119122 }
120123
@@ -206,15 +209,6 @@ class SpatialAudioMain: BaseViewController {
206209
207210 func updatePosition( ) {
208211 let pos = getViewCenterPostion ( view: selfPostionView)
209- print ( " pos === \( pos) " )
210- print ( " selfPostionVieWFrame === \( selfPostionView. frame) " )
211- print ( " attenuationFrame == \( voiceContainerView1. frame) " )
212- print ( " mediaPlayer1 === \( voiceButton1. frame) " )
213- print ( " mediaPlayer2 === \( voiceButton2. frame) " )
214- let isContaninerPlayer = voiceContainerView1. frame. contains ( voiceButton1. frame)
215- print ( " attenuation player === \( isContaninerPlayer) " )
216- let isContainer = voiceContainerView1. frame. contains ( selfPostionView. frame)
217- print ( " isContainer === \( isContainer) " )
218212 localSpatial. updateSelfPosition ( pos, axisForward: forward, axisRight: right, axisUp: up)
219213 }
220214
0 commit comments