Adding MPVolumeview programmatically in app

user1452248 picture user1452248 · Sep 2, 2012 · Viewed 7k times · Source

Trying to add MPVolumeView programmtically in app by using the following code

 MPVolumeView *_volumeView = [ [MPVolumeView alloc] init];
[_volumeView setShowsVolumeSlider:YES];
[_volumeView setShowsRouteButton:YES];
[_volumeView sizeToFit];
[view addSubview:_volumeView];

but getting so many Semantic issue that use of undeclared identifier MPVolumeView and Invalid operands to binary expression

@property (nonatomic, strong) MPVolumeView *volumeView;

Getting message in red for the above statement that unknown type MPVolumeView and plus property with retain or strong must be of object type.

 @synthesize volumeView = _volumeView;

Is this the right way to add MPVolumeView programmatically in app.

Thanks for help.

Answer

Rengers picture Rengers · Sep 2, 2012

MPVolumeView is part of the MediaPlayer framework. Did you include this in your application and did you #import <MediaPlayer/MediaPlayer.h> in your .m or .h file?

Also, if you declared a property, you should create a new local variable _volumeView. Replace the first line with this:

_volumeView = [ [MPVolumeView alloc] init];