Hold and Release in Xcode (Sound)? - ios

So, I just basically want to use AVFoundation Kit for playing my sound. I have the play method set, but I want to be able to hold down the button and play the sound that way rather than tapping it first. Once I release the button, I want the sound to stop. Simple: Hold down to play sound and then release your finger to stop the sound like a piano. Help please! Thanks.

If you right click on the button in IB you should be able to link the
Touch down
and
Touch Cancelled
button links so that it they both call the same method or they each call a different method one to stop the sound and one to start it.
you might also want to check out this
forum
hope this helps

Related

How do I keep my video player working in flutter?

When I use the video_player plugin, I use the Navigator.push function to go to another screen where I push a button to display the video. Once the video is over, I push the back button. If I activate the Navigator.push function again and push the button to display the video, no visual is shown and only the audio is played. Can someone tell me what is going on and how to fix this?
Never mind, I found out that the issue was that I needed to call setState before I could display the video the second time.

Strange behaviour in iOS Today Widget with AVPlayer

I'm really getting crazy on this, so I'd ask for some help.
I'm coding a little widget that presents two UIButton the user can tap, once pressed the widget adds a notification to the app, if the button is pressed again the notification will be deleted.
Initially I added a sound to the touch of the button and worked ok with AVPlayer, then I decided to use the haptic engine to give feedback to the user so I deleted the AVPlayer call to stop the sound: guess what? the button continues to play the sound! I've commented the code I used to play the sound, how can it still play the sound?.
The strange thing is that one button has got this strange behaviour, while the other just works fine (only haptic engine), it sounds like a bug but I'm a rookie and it should be my fault somewhere.
Any idea?

How can i make the button about audio in Xcode?

I want to make a useful dictionary.
So, i want to make a audio button and put some audio to button.
but, it's a not say. i don't have a skill in Xcode.
i need to help to me about make a audio button and put some audio to button in Tableview.
I want to create audio buttons for each.
I don't know this website system and i upload picture in Dropbox.
Have nice day.
enter link description here
I would add a "AVAudioPlayer *audio" to your recipe object that you play when the button "Play Audio" is pressed.

How to change the background music as soon as the game starts?

Hey so I am playing some background music as soon as my app starts. Like a menu song, and it is looping forever throughout the game. I would like to change the music as soon as you hit the start game button. Just so I can have a different menu and game songs. I tried
backgroundMusicPlayer.play()
playBackgroundMusic("MUSIC.wav")
I did this in my touchesBegan method but of course every time you touch the screen the song is going to start over and over again. Any ideas how I can do this? Thank you in advance
While the game starts,if a user touches the initial screen,then it could be identified with a tapGestureRecognizer,in the corresponding class file.
I prefer tap recognising than touchesBegan ,so that, when user touches the screen ,you could play the music via
backgroundMusicPlayer.play()
playBackgroundMusic("MUSIC.wav")
and stop this by backgroundMusicPlayer.stop()when moving on to MENU page.
Then the music wont get played everytime user touches the screen.
I hope this works.
Simply use AVFoundation. Follow this basic tutorial to play audio as soon as the ViewController loads, then on clicking the start button stop the audioPlayer.

MPMusicPlayerController: combine iPodMusicPlayer and applicationMusicPlayer to prevent continuing to next track

I have a bit of a strange problem. I have a music app that uses the [MPMusicPlayerController iPodMusicPlayer]. Everything is fine, notifications are fired for track changes and changes in playback state.
I have one screen where the user needs to review one single song, I don't want him to go on to the next song in his queue. Since there is no delegate method for when a track WILL change (only DID change), to prevent the music player from continuing to the next track I use a new [MPMusicPlayerController applicationMusicPlayer], give it iPodMusicPlayer's currently playing song and all is well. No new tracks to continue to, and I'm not touching the original iPodMusicPlayer queue so in theory, when I close this screen and use the iPodMusicPlayer again, all should be perfectly fine.
However, when the user is done on this screen and closes it, iPodMusicPlayer is now suddenly broken, notifications are not called and when I put the app to the background, music stops playing, causing me to believe that iPodMusicPlayer is now actually applicationMusicPlayer.
Okay so my question is basically: I need a way to prevent the music player to continue on to the next track in the queue. Switching to applicationMusicPlayer with one track seems to break stuff, as explained above. What's the best solution?
EDIT: because this might be a bit difficult to understand, I created a small project to show the problem: https://github.com/kevinrenskers/MPMusicPlayerControllerTest. Open the app while music is playing, see that the play button behaves correctly. Now open the popup, close it again and the play button is broken.
I found a solution to my problem: set the repeatMode to MPMusicRepeatModeOne and then catch the MPMusicPlayerControllerNowPlayingItemDidChangeNotification notification. You can stop the playback and you never continue to the next track. Once I'm done with the second screen I reset the repeatMode to the original value.

Resources