ios - AVPlayer wont play video from url in iOS9 -
i trying embed avplayer inside uiview , play mp4 video file url. problem receive black blank view (see screenshot)
in previous ios versions worked me, since upgrading ios9 got problem.
my .h file looks this:
@interface viewcontroller : uiviewcontroller @property (strong, nonatomic) iboutlet uiview *viewplayercontainer;
whereas in implementation file have following:
@import avfoundation; @import avkit; @interface viewcontroller () @end @implementation viewcontroller - (void)viewdidload { [super viewdidload]; avplayerviewcontroller *playerviewcontroller = [[avplayerviewcontroller alloc] init]; nsurl *url = [nsurl urlwithstring:@"http://techslides.com/demos/sample-videos/small.mp4"]; avurlasset *asset = [avurlasset assetwithurl: url]; avplayeritem *item = [avplayeritem playeritemwithasset: asset]; avplayer * player = [[avplayer alloc] initwithplayeritem: item]; [playerviewcontroller.view setframe:cgrectmake(0, 0, _viewplayercontainer.bounds.size.width, _viewplayercontainer.bounds.size.width)]; playerviewcontroller.showsplaybackcontrols = no; [_viewplayercontainer addsubview:playerviewcontroller.view]; [player play]; }
am missing here?
thanks in advance!
@implementation viewcontroller{ avplayerviewcontroller *playerviewcontroller; } - (void)viewdidload { [super viewdidload]; playerviewcontroller = [[avplayerviewcontroller alloc] init]; } - (ibaction)playvideo:(id)sender { nsurl *url = [nsurl urlwithstring:@"http://techslides.com/demos/sample-videos/small.mp4"]; avurlasset *asset = [avurlasset assetwithurl: url]; avplayeritem *item = [avplayeritem playeritemwithasset: asset]; avplayer * player = [[avplayer alloc] initwithplayeritem: item]; playerviewcontroller.player = player; [playerviewcontroller.view setframe:cgrectmake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width)]; playerviewcontroller.showsplaybackcontrols = yes; [self.view addsubview:playerviewcontroller.view]; [player play]; }
Comments
Post a Comment