ios


How to play a sound from an array when tap a button in a collection view cell in Swift 3?


USING iOS SWIFT 3
I have developed a custom keyboard using a collectionView. Each collectionViewCell has a button inside from an array of buttons created in my code - When user taps this button I would like the appropriate sound from the array of sounds also created in my code to play....the arrays are set up so that the array of buttons corresponds directly to the array of sounds
for instance
var buttons = ["1", "2", "3", "4"]
var sounds = ["sound1", "sound2", "sound3", "sound 4"]
I have managed to get the sounds playing from the array in random order, but I want the sounds to play in order of the array - so when user taps button 1, sound1 will play....when user taps button 2, sound2 will play etc
At the moment on the iOS simulator when user taps button 1, any one of the above sounds is picked at random to play
here is the code I have used when user taps button in collectionViewCell sounds play randomly rather than matching to the order of the "sounds" array. FYI in the below code "Sounds" is the array of sounds I have created
#IBAction func cellButton(_ sender: AnyObject) {
let range: UInt32 = UInt32(Sounds.count)
let number = Int(arc4random_uniform(range))
self.setupAudioPlayer(file: Sounds[number] as NSString, type: ".m4a")
self.soundPlayer.play()
}

Related Links

How to load txt file to UITextView with attributedString?
How to track In-App Refund in ios app [duplicate]
Displaying custom keyboard build with storyboard on iOS
“Core Data could not fulfill a fault for…”
Swift Optional Type not Unwrapped
UIScrollView Height and width
iOS - SFSafariViewController Freezes/Hanging
MTAudioProcessingTap - produce more output samples?
Localizable file isn't working on device
Parse email verification error with Swift 2
How to change Device Identity Certificate(SCEP certificate)'s expiration date in OS X Server App(for Profile Manager)
Change background color of title (only) in UIAlertController
Can't Xcode7.1 code sign with certificate?
iOS 8 vs iOS 9 Appdelegate / ViewController method call flow
How to Remove and Adding Constraints when we change simulator orientation(like portrait to landscape) in ios
Parse column value of class is always nil

Categories

HOME
sbt
azure
wpf
matlab
whatsapp
bootstrap-4
angular2-forms
module
orbeon
passwords
localforage
runtime-error
antlr
addeventlistener
spi
android-dialer
classloader
tin-can-api
intl
vscode-settings
numericupdown
fbx
apache-kafka-streams
teamcity-9.0
spring-restdocs
pwm
code-analysis
deadbolt
ibm-datapower
aspdotnetstorefront
csom
liferay-aui
confidence-interval
padding
rets
grouping
fat-free-framework
angular-ngmodel
editorconfig
opensuse
rdf4j
dapper-fastcrud
pmd
mobile-center
complex-networks
nib
nio
vtable
angular-xeditable
solid-principles
spring-saml
rft
uitabbarcontroller
wp-api
integer-programming
pulseaudio
pseudo-element
xbrl
reactivex
easyhook
getelementbyid
masspay
topojson
evaluate
git-config
jsbin
printscreen
pygments
blpapi
gcloud-java
oracle-bi
heroku-toolbelt
tabbar
equinox
iphone-5
abort
easynetq
words
imake
nolio
sbrk
formhelper
prettyfaces
globus-toolkit
css3pie
validform
qt4.7
sqlprofiler
prudentia
datapump
pubdate
qdebug
progressdialog
haar-wavelet
calloc
onmouseout
jsr223
arden-syntax
j#
self-organizing-maps
proxy-classes
consistent-hashing
azure-role-environment
f2c
pong
treetop
keylogger
large-teams

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App