gpt4 book ai didi

ios - 视频不在 GMSMarker 上播放

转载 作者:技术小花猫 更新时间:2023-10-29 11:25:41 25 4
gpt4 key购买 nike

我正在 GMSMarker pin 上播放视频,下面是我的代码。显示和隐藏/显示引脚 View ,一切正常。除了视频不播放。我正在使用带有 pinview 的 Storyboard。

@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];
}

enter image description here

enter image description here

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

提前致谢。

最佳答案

通常情况下,信息窗口在显示(添加为图像)后不会重新生成。要显示视频帧,它需要在视频播放时重新生成。这意味着窗口需要自动刷新。为此,您需要为 GMSMarker 设置一个属性。行如下,

    _london.tracksInfoWindowChanges = YES;

所以你的完整代码是

CLLocationCoordinate2D position = CLLocationCoordinate2DMake(51.5, -0.127);
_london = [GMSMarker markerWithPosition:position];
_london.title = @"London";
_london.tracksViewChanges = YES;
_london.tracksInfoWindowChanges = YES;
_london.map = self.mapView;

Google 文档是 https://developers.google.com/maps/documentation/ios-sdk/marker#set_an_info_window_to_refresh_automatically

关于ios - 视频不在 GMSMarker 上播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46012443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com