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 8383595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:12:05+00:00 2026-06-09T17:12:05+00:00

How to have a Slider in a class view controller that changes the volume

  • 0

How to have a Slider in a class view controller that changes the volume of a song playing in the AppDelage, in Objective-C for iOS?
Here is my code in the .h AppDelegate

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface JARAppDelegate : UIResponder <UIApplicationDelegate>
{
    AVAudioPlayer *musicPlayer;
}

@property (strong, nonatomic) UIWindow *window;

- (void)playMusic;
- (void)setVolume:(float)vol;

@end

And in the .m:

- (void)playMusic
{

    NSString *musicPath = [[NSBundle mainBundle] pathForResource:@"The History of the World" ofType:@"mp3"];
    NSURL *musicURL =  [[NSURL alloc] initFileURLWithPath:musicPath];

    musicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:musicURL error:nil];
    [musicPlayer setNumberOfLoops:-1];   // Negative number means loop forever
    [musicPlayer setVolume:1.0];

    [musicPlayer prepareToPlay];
    [musicPlayer play];
    NSLog(@"play");
}

- (void)setVolume:(float)vol
{
    [musicPlayer setVolume:vol];
}

and when ‘didFinishLaunchingWithOptions’ I call [self playMusic];
This works and plays the song I want a full volume! Then in a different class called SettingsViewControler:
The .h

#import <UIKit/UIKit.h>
#import "JARAppDelegate.h"

@interface JARSettingsViewController : UIViewController
{

}

@property (strong, nonatomic) IBOutlet UISlider *volumeSliderOutlet;

- (IBAction)volumeSliderActoin:(id)sender;

@end

The .m:

- (IBAction)volumeSliderActoin:(id)sender
{
     NSLog(@"Volume Changed");
     [JARAppDelegate setVolume:sender];
}

Volume Changed is logged everytime you move the slider up and down, and so it should be sending setVolume a value between 0.0 and 1.0. But I get an error that says “No known class method for selector ‘setVolume:’

  • 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-06-09T17:12:06+00:00Added an answer on June 9, 2026 at 5:12 pm

    This is because you are trying to invoke a class method when you call:

    [JARAppDelegate setVolume:sender];
    

    but this doesn’t exist. You have created an instance method.

    Try creating a singleton for the AVAudioPlayer, then you could do the following:

    [[AVAudioPlayer sharedInstance] setVolume:vol];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some view controller, that uses my own view class and XIB interface,
I have a custom UIView class. Inside that view, there is an image view.
In code below is function that converts slider class into slider control. It has
I have an Advertisement UIViewController class that contains the following code. The frame is
I have an slider that ads an class (.current-item) to each tab that is
I have the following model associations: class Slider < ActiveRecord::Base has_one :featured_happening, :as =>
I have Slider in my app that is connected to a few methods. In
I have a slider that has a fade-in and fade-out transition. It basically cycles
I have a slider that returns values from 0.0f to 1.0f. I want to
I have a view with a custom slider. We are using a subclass of

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.