diff --git a/proj.ios/Double Hit Balls.xcodeproj/project.pbxproj b/proj.ios/Double Hit Balls.xcodeproj/project.pbxproj index 8e0c452..0512f6f 100755 --- a/proj.ios/Double Hit Balls.xcodeproj/project.pbxproj +++ b/proj.ios/Double Hit Balls.xcodeproj/project.pbxproj @@ -32,6 +32,10 @@ 84D0FEBE1E274DDD00EC3FE5 /* libSalmon Engine.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C902A7815C5735700FBC901 /* libSalmon Engine.a */; }; 84D0FEC91E274E4A00EC3FE5 /* libvorbis-tremor-ios.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D0FEC61E274E3700EC3FE5 /* libvorbis-tremor-ios.a */; }; 84D0FECC1E274EBC00EC3FE5 /* main_code.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84D0FECA1E274EBC00EC3FE5 /* main_code.cpp */; }; + AC67C87D211C8DD3003AA164 /* NativeSoundCalls.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC67C87C211C8DD3003AA164 /* NativeSoundCalls.swift */; }; + AC67C87F211C8DE3003AA164 /* NativeSoundCallsImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC67C87E211C8DE3003AA164 /* NativeSoundCallsImpl.swift */; }; + AC67C882211C8E24003AA164 /* gunshot_sound.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = AC67C880211C8E24003AA164 /* gunshot_sound.mp3 */; }; + AC67C883211C8E24003AA164 /* background_sound.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = AC67C881211C8E24003AA164 /* background_sound.mp3 */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -103,6 +107,10 @@ 84D0FEC11E274E3700EC3FE5 /* vorbis-tremor-ios.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "vorbis-tremor-ios.xcodeproj"; path = "../../libs/vorbis-tremor-ios/vorbis-tremor-ios.xcodeproj"; sourceTree = ""; }; 84D0FECA1E274EBC00EC3FE5 /* main_code.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main_code.cpp; path = ../game/main_code.cpp; sourceTree = ""; }; 84D0FECB1E274EBC00EC3FE5 /* main_code.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = main_code.h; path = ../game/main_code.h; sourceTree = ""; }; + AC67C87C211C8DD3003AA164 /* NativeSoundCalls.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeSoundCalls.swift; sourceTree = ""; }; + AC67C87E211C8DE3003AA164 /* NativeSoundCallsImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeSoundCallsImpl.swift; sourceTree = ""; }; + AC67C880211C8E24003AA164 /* gunshot_sound.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = gunshot_sound.mp3; sourceTree = ""; }; + AC67C881211C8E24003AA164 /* background_sound.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = background_sound.mp3; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -128,6 +136,8 @@ 4C49B2AE15B0991B003512CD = { isa = PBXGroup; children = ( + AC67C881211C8E24003AA164 /* background_sound.mp3 */, + AC67C880211C8E24003AA164 /* gunshot_sound.mp3 */, 84D0FEC11E274E3700EC3FE5 /* vorbis-tremor-ios.xcodeproj */, 4C902A7015C5735500FBC901 /* Salmon Engine.xcodeproj */, 4C7B819515C40F770024D61A /* Libs */, @@ -217,6 +227,7 @@ 4CE6A9E315B2F9A4006A3965 /* Game */ = { isa = PBXGroup; children = ( + AC67C87B211C8DB6003AA164 /* sounds */, 74C3AE251E2E2A40003C07F2 /* creditscode.cpp */, 74C3AE261E2E2A40003C07F2 /* creditscode.h */, 74C3AE271E2E2A40003C07F2 /* game_area_interface.h */, @@ -240,6 +251,15 @@ name = Products; sourceTree = ""; }; + AC67C87B211C8DB6003AA164 /* sounds */ = { + isa = PBXGroup; + children = ( + AC67C87C211C8DD3003AA164 /* NativeSoundCalls.swift */, + AC67C87E211C8DE3003AA164 /* NativeSoundCallsImpl.swift */, + ); + name = sounds; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -326,6 +346,8 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + AC67C882211C8E24003AA164 /* gunshot_sound.mp3 in Resources */, + AC67C883211C8E24003AA164 /* background_sound.mp3 in Resources */, 841270C91E639C2F00776DAE /* Images.xcassets in Resources */, 841D49651E65981600C85722 /* LaunchScreen.storyboard in Resources */, 4C49B2CC15B0991B003512CD /* InfoPlist.strings in Resources */, @@ -345,12 +367,14 @@ 74EEBAEF1E2D13A6004C6C65 /* AppDelegate.swift in Sources */, 74C3AE2E1E2E2A40003C07F2 /* creditscode.cpp in Sources */, 74C3AE2F1E2E2A40003C07F2 /* gamecode.cpp in Sources */, + AC67C87D211C8DD3003AA164 /* NativeSoundCalls.swift in Sources */, 74EEBAF11E2D1C7C004C6C65 /* CustomGLKView.swift in Sources */, 84D0FECC1E274EBC00EC3FE5 /* main_code.cpp in Sources */, 74C3AE301E2E2A40003C07F2 /* loadingcode.cpp in Sources */, 74AC9EBD1E2CE407003C9749 /* ViewController.swift in Sources */, 74AC9EC11E2CF533003C9749 /* SENamespaceWrapper.cpp in Sources */, 74C3AE311E2E2A40003C07F2 /* menucode.cpp in Sources */, + AC67C87F211C8DE3003AA164 /* NativeSoundCallsImpl.swift in Sources */, 4C7AD44C15B1D77700A599F6 /* ios_api.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/proj.ios/NativeSoundCalls.swift b/proj.ios/NativeSoundCalls.swift new file mode 100644 index 0000000..906b6da --- /dev/null +++ b/proj.ios/NativeSoundCalls.swift @@ -0,0 +1,11 @@ +import Foundation + +protocol NativeSoundCalls { + + func playBackgroundSound() + func stopBackgroundSound() + + func playGunshotSound() + func stopGunshotSound() + +} diff --git a/proj.ios/NativeSoundCallsImpl.swift b/proj.ios/NativeSoundCallsImpl.swift new file mode 100644 index 0000000..46696fb --- /dev/null +++ b/proj.ios/NativeSoundCallsImpl.swift @@ -0,0 +1,54 @@ +import Foundation +import AVFoundation + +// example sounds for native calls +// Created by Artem Budarin on 08.08.2018. + +public class NativeSoundCallsImpl : NativeSoundCalls { + + var backgroundPlayer: AVAudioPlayer? + var gunshotPlayer: AVAudioPlayer? + + func playBackgroundSound() { + guard let url = Bundle.main.url(forResource: "background_sound", withExtension: "mp3") else { return } + do { + try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback) + try AVAudioSession.sharedInstance().setActive(true) + backgroundPlayer = try AVAudioPlayer(contentsOf: url) + + //swift 4 + //backgroundPlayer = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileType.mp3.rawValue) + + backgroundPlayer?.numberOfLoops = NSInteger.max + backgroundPlayer?.play() + } catch let error { + print(error.localizedDescription) + } + } + + func stopBackgroundSound() { + backgroundPlayer?.stop() + } + + func playGunshotSound() { + guard let url = Bundle.main.url(forResource: "gunshot_sound", withExtension: "mp3") else { return } + do { + try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback) + try AVAudioSession.sharedInstance().setActive(true) + gunshotPlayer = try AVAudioPlayer(contentsOf: url) + + //swift 4 + //gunshotPlayer = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileType.mp3.rawValue) + + gunshotPlayer?.play() + } catch let error { + print(error.localizedDescription) + } + } + + func stopGunshotSound() { + gunshotPlayer?.stop() + } + +} + diff --git a/proj.ios/background_sound.mp3 b/proj.ios/background_sound.mp3 new file mode 100755 index 0000000..ead9299 Binary files /dev/null and b/proj.ios/background_sound.mp3 differ diff --git a/proj.ios/gunshot_sound.mp3 b/proj.ios/gunshot_sound.mp3 new file mode 100755 index 0000000..ae35066 Binary files /dev/null and b/proj.ios/gunshot_sound.mp3 differ