我正在构建收音机 APP,我已将 UIView 添加到我的 ViewController 并将其类更改为 MPVolumeView。当我在我的设备上测试它时会出现滑块,但对触摸手势没有响应。奇怪的是,它通过音量按钮响应硬件变化。这是我的代码:
#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;
还有他们。文件:
@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];
}
感谢您提供解决此问题的任何提示和建议。我花了几个小时试图找到一个没有任何运气的解决方案。