Domanda

I am building radio APP, I have added UIView to my ViewController and changed its class to MPVolumeView. The slider appears when I test it on my device but is non-responsive to touch gestures. What's weird is that it responds to hardware change with the volume buttons. Here is my code:

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


@interface ViewController : UIViewController{
MPVolumeView *_mpVolumeView;
}


 - (IBAction)playPressed:(id)sender;
@property (strong, nonatomic) IBOutlet MPVolumeView *mpVolumeView;

And the m. file:

@interface ViewController ()
 {
AVPlayer *vPlayer;
}
@end

@implementation ViewController
@synthesize mpVolumeView = _mpVolumeView;


- (void)viewDidLoad
{
[super viewDidLoad];

NSURL *vibes = [NSURL URLWithString:@"http://vibesradio.org:8002/listen.pls"];
vPlayer = [[AVPlayer alloc] initWithURL:vibes];

_mpVolumeView.backgroundColor = [UIColor clearColor];
MPVolumeView *myVolumeView = [[MPVolumeView alloc] initWithFrame: _mpVolumeView.bounds];
[_mpVolumeView addSubview:myVolumeView];
}

Thanks for any tips and suggestions to fix this issues. I have spent several hours trying to find a solution without any luck.

È stato utile?

Soluzione

You may want to change:

MPVolumeView *myVolumeView = [[MPVolumeView alloc] initWithFrame: _mpVolumeView.bounds];
[_mpVolumeView addSubview:myVolumeView];

towards:

self.myVolumeView = [[MPVolumeView alloc] initWithFrame:CGRectZero];
[self.myVolumeView sizeToFit];
[self.view addSubview:self.myVolumeView];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top