iphone - MPMoviePlayerViewController not playing video or displaying controls -


here's code should playing video embedded in subview, displays still image no controls.

- (void)displayvideo:(nsurl *)videourl {     if (self.mediaplayer) {         [self.mediaplayer.view removefromsuperview];         self.mediaplayer = nil;     }      self.mediaplayer = [[mpmovieplayerviewcontroller alloc] initwithcontenturl:videourl];     [self.mediaplayer.movieplayer preparetoplay];     self.mediaplayer.movieplayer.controlstyle = mpmoviecontrolstyleembedded;     self.mediaplayer.view.frame = cgrectmake(0, 0, self.mediaview.bounds.size.width, self.mediaview.bounds.size.height);     [self.mediaview addsubview:self.mediaplayer.view];     [self.mediaplayer.movieplayer play]; } 

i tried load media player directly mediaplayer mpmovieplayercontroller instead of mpmovieplayerviewcontroller, less black view.

    self.mediaplayer = [[mpmovieplayercontroller alloc] initwithcontenturl:videourl];     [self.mediaplayer preparetoplay];     self.mediaplayer.movieplayer.controlstyle = mpmoviecontrolstyleembedded;     self.mediaplayer.view.frame = cgrectmake(0, 0, self.mediaview.bounds.size.width, self.mediaview.bounds.size.height);     [self.mediaview addsubview:self.mediaplayer.view];     [self.mediaplayer play]; 

thanks help.

the first code wrong. way use mpmovieplayerviewcontroller presented view controller (presentviewcontroller:...); must not grab view , try shove own interface.

the second 1 stands better chance. here things think about:

  • is videourl valid? how know? no, seriously. , think format, too, since not every video format playable under ios.

  • is self.mediaplayer retaining movie player controller? again, carefully; that's crucial. must have strong or retain policy.

  • do have other media player controller views in interface? notice in second code forgot remove previous one. crucial! there can 1 such view.

(by way, there no need ask mpmoviecontrolstyleembedded; default in configuration.)

finally, might compare working code. code in book does work:

http://www.apeth.com/iosbook/ch28.html#_mpmovieplayercontroller

nsurl* m = [[nsbundle mainbundle] urlforresource:@"elmirage"                                    withextension:@"mp4"]; mpmovieplayercontroller* mp =     [[mpmovieplayercontroller alloc] initwithcontenturl:m]; self.mpc = mp; // retain policy self.mpc.shouldautoplay = no; [self.mpc preparetoplay]; self.mpc.view.frame = cgrectmake(10, 10, 300, 250); self.mpc.backgroundview.backgroundcolor = [uicolor redcolor]; [self.view addsubview:self.mpc.view]; 

and can prove downloading example:

https://github.com/mattneub/programming-ios-book-examples/tree/master/ch28p786movieplayer


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -