【发布时间】:2017-09-02 09:39:03
【问题描述】:
我正在 GMSMarker pin 上播放视频,下面是我的代码。显示和隐藏/显示引脚视图,一切正常。除了视频不能播放。我正在使用带有 pinview 的故事板。
@interface MapViewController () <GMSMapViewDelegate>
@property (strong, nonatomic) IBOutlet GMSMapView *mapView;
@property (strong, nonatomic) IBOutlet UIView *pinView;
@property (strong, nonatomic) GMSMarker *london;
@property (strong, nonatomic) AVPlayer *player;
@property (strong, nonatomic) AVPlayerLayer *playerLayer;
@end
@implementation MapViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:51.5 longitude:-0.127 zoom:18];
self.mapView.camera = camera;
self.mapView.delegate = self;
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(51.5, -0.127);
_london = [GMSMarker markerWithPosition:position];
_london.title = @"London";
_london.tracksViewChanges = YES;
_london.map = self.mapView;
[self setUpVideoPlayer];
}
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
[self.player play];
return self.pinView;
}
-(void)setUpVideoPlayer{
NSString *videoFilePath = [[NSBundle mainBundle] pathForResource:@"SampleVideo" ofType:@"mp4"];
AVAsset *avAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:videoFilePath]];
AVPlayerItem *avPlayerItem =[[AVPlayerItem alloc]initWithAsset:avAsset];
self.player = [[AVPlayer alloc]initWithPlayerItem:avPlayerItem];
self.playerLayer =[AVPlayerLayer playerLayerWithPlayer:self.player];
[self.playerLayer setFrame:self.pinView.frame];
[self.pinView.layer addSublayer:self.playerLayer];
[self.player seekToTime:kCMTimeZero];
}
请帮我解决这个问题。为什么视频没有播放。
提前致谢。
【问题讨论】:
-
您可以将您的代码发布为 Code 吗?
-
@ReinierMelian 我已经更新了我的代码,请你检查一下我到底在哪里做错了。
-
如果提供的答案解决了您的问题,请告诉我,如果没有,我会尽力帮助您,最好的问候
-
检查我的编辑,我在模拟器上看到了视频,但它在真实设备上不起作用。但即使它有效,用户也无法播放/支付视频,因为它不是播放器,它是图像(播放器的屏幕截图)
标签: ios objective-c google-maps video gmsmapview