视频不适用于GMSMarker

Thu*_*ram 9 video google-maps objective-c ios gmsmapview

我正在GMSMarker引脚上播放视频,下面是我的代码.显示和隐藏/显示引脚视图,一切正常.视频不播放除外.我正在使用带有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];
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在此输入图像描述

请帮我解决这个问题.为什么视频没有播放.

提前致谢.

Vla*_*nic 1

我相信您的代码不起作用的原因是Google Maps for iOS 将 Custom Info Views 呈现为 Images。我不确定,但我相信,因为我也尝试过动画,但它也不起作用。当我使用动画时,我首先看到动画的初始状态,当我再次打开标记信息窗口时,我看到最终状态,没有动画。另外,当我在自定义信息窗口视图上添加文本字段时,我无法单击该文本字段。当我尝试像您一样播放视频时,我看到一个空白窗口,就像播放器将要启动并听到声音一样,但视频从未开始。

我在 Stackoverflow 上的许多问题上找到了这个注释(他们说它来自 Google Docs),但我在 Google Docs 上没有看到它:

注意:信息窗口每次在地图上显示时都会呈现为图像。这意味着,当其处于活动状态时,对其属性的任何更改都不会立即可见。信息窗口的内容将在下次显示时刷新。

来源:Google 地图 iOS 标记信息窗口中显示语音气泡

也许你可以尝试使用 trackInfoWindowChanges = YES:

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
     marker.tracksInfoWindowChanges = YES;
     self.player play];
     return self.pinView;
}
Run Code Online (Sandbox Code Playgroud)

来源:如何强制刷新Google Maps iOS SDK中markerInfoWindow的内容

我知道你已经在viewDidLoad方法中设置了它,但也许在方法中设置它
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker 可能会起作用,但我不相信。很多人说设置markerInfoWindow成YES就可以了,但是我试过了,还是不行。

我尝试使用 iOS 地图和视频播放,没有出现任何问题。我在使用 Apple 地图时从未遇到过问题。所以,我确信谷歌地图并不是解决这个问题的好方法。也许你可以通过一些技巧来修复它,但我花了几个小时来寻找解决方案,但没有结果。也许可以做到,例如,当用户在地图上移动手指或放大/缩小时,将 UIView 移动到地图上方,或者其他一些解决方案,但我更喜欢系统解决方案而不是黑客。在这种情况下,我没有看到系统解决方案,如果我花更多时间研究,也许我会找到它。如果我是你,我就不会使用谷歌地图。

编辑:我刚刚看到我的解决方案可以在模拟器上运行。在真实设备(iPhone 7+)上它不起作用,即我看到播放器控件有动画,我看到声音,但看不到视频。但即使它像在模拟器上一样在真实设备上运行,用户也无法播放或暂停视频,因为他只能看到定期更新的图像。