Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6644313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:09:11+00:00 2026-05-26T00:09:11+00:00

I’m trying to do an app where a short sound sample is supposed to

  • 0

I’m trying to do an app where a short sound sample is supposed to be played while the person using the app is dragging his/her finger(s) across the screen. When the finger(s) are lifted away from the screen – the sound will stop.

This is the function that triggers the sound:

-(IBAction) playSound:(id)sender{

NSString *soundPath = [[NSBundle mainBundle]pathForResource:@"sound" ofType:@"wav"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundPath];

newPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:fileURL error:nil];
newPlayer.numberOfLoops = -1;
[newPlayer play];   
}

This is the function that stops the sound:

-(IBAction) stopSound{
if ([newPlayer isPlaying]) {
    [newPlayer stop];
}
[newPlayer release];
}

I first started out using the Touch Down event, which looped the sound seamlessly. At this point the stopSound worked together with the “Touch Up Inside” event.

The point, as I said, is the sound is supposed to be generated when the user drags his/her finger(s) across the screen. But when I tried to the tie the playSound function to the “Touch Drag Inside” the sound loops repeatedly over itself, instead of one at the time, making it hell to use. The stopSound function doesn’t work after i changed to the Drag Event.

I tried to use NSTimer to create some kind of way to handle the loops, but without any success.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:09:11+00:00Added an answer on May 26, 2026 at 12:09 am

    My advice would be to create to generate a method that loops your audio clip (whatever duration, overlap, pausing, etc you want). Setup the method so that when you call it to play, it plays the way you want it to indefinitely.

    The method might look like:

    -(void) beginOrContinuePlayingAudioLoop:(BOOL)shouldPlay {
    
     //if touchesMoved called, shouldPlay will be YES
     //if touchesEnded called, shouldPlay will be NO
    
     if (shouldPlay == NO) {
     //cease playing
     currentlyPlaying = NO;
     }
    
    if (currentlyPlaying == YES) {
    
    return;
    
    } else {
    
    //begin playing audio
    currentlyPlaying = YES;
    
     }
    }
    

    In your ViewController class, define a BOOL (currentlyPlaying) that indicates whether the audio loop is currently playing.

    As opposed to using canned IBAction gesture recognizers, consider overriding the more generic touch responder calls, touchesMoved and touchesEnded on your view.

    In touchesMoved, set your VC’s BOOL to YES and then fire your audio looping method to start playing. The “playing” method should always check and see if the audio is already playing, and only start playing

    Also place a check in your method that returns/exits your method when the audio loop is already playing, this will avoid overlapping.

    In touchesEnded, kill your audio via whatever method you choose, and reset the BOOL to NO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.