Play movies on iOS and Android

Source: Internet
Author: User

Ios

//

Movieplayercontroller.h

Sgcard

//

Created by Apple on 13-9-10.

//

//

#import <MediaPlayer/MediaPlayer.h>

#import "Movieplayer.h"

#import "EAGLView.h"

@interface Movieplayercontorl: NSObject <uiaccelerometerdelegate , Uialertviewdelegate, uitextfielddelegate, uiapplicationdelegate>

{

UIWindow *window;

MPMoviePlayerController* moviecontroller;

cmovieplayer * movieplayer;

//eaglview *view;

UIButton * btnjump;

}

-(void) PlayVideo: (cmovieplayer*) Movie: (nsstring*) strFileName: (nsstring*) Strfiletype;

-(void) finished: (ID) sender;

-(void) Jumpover: (ID) sender;

-(void) play;

// used to call the following function before the program hangs when the Home key is clicked on the iPhone

-(void) Applicationsuspend: (nsnotification *) notification;

// when the pending program re-enters the runtime, the following function is called

-(void) applicationresumed: (nsnotification *) notification;

@end

//

Movieplayercontroller.cpp

Sgcard

//

Created by Apple on 13-9-10.

//

//

#import "Movieplayercontroller.h"

#import "Cocos2d.h"

#import "GameAdapt.h"

used to get the information in Gameinfo

#import ". /.. /data/gameinfo.h "

UsingNamespacesgcard;

UsingNamespacecocos2d;

@implementation Movieplayercontorl

-(void) PlayVideo: (cmovieplayer*) Movie: (nsstring*) strFileName: (nsstring*) Strfiletype

{

MoviePlayer = movie;

nsstring *path = [[nsbundle mainbundle] pathforresource : strFileName OfType : Strfiletype];

Moviecontroller = [[MPMoviePlayerControlleralloc] initwithcontenturl: [ nsurlfileurlwithpath:p Ath]];

nsnotificationcenter* notification = [nsnotificationcenterdefaultcenter];

[Notification addobserver : self selector:@selector(finished:) name :mpmovieplayerplaybackdidfinishnotificationobject : moviecontroller];

moviecontroller. Scalingmode = Mpmoviescalingmodeaspectfill;

moviecontroller. ControlStyle = Mpmoviecontrolmodedefault;

// The following code sets the interface size of the playback animation, since the size of the iPhone is 1 times worse than the true size, and the ipad is equal

ccsize size = cgameadapt::get(),size();

// bring the view and window object Generation forward here for the following code needs

//view = [Eaglview Sharedeglview];

// and Window.screen.scale is 2 in IPhone, 1 in ipad. specific relationship may be asked to do the iOS screen adaptation of the person

window = [[uiwindow alloc] initWithFrame: [[uiscreen mainscreen] Bounds]];

float coeffi = cgameadapt::get(),coefficient();

float x = cgameadapt::get(),x()/ window. screen. Scale;

float y = cgameadapt::get(),y()/ window. screen. Scale;

float width = (size. Width * coeffi)/ window. screen. Scale;

float height = (size. Height * coeffi)/ window. screen. Scale;

[Moviecontroller. View setframe:cgrectmake(x, y, width, height)];

[moviecontroller. Viewsetbackgroundcolor : [uicolorclearcolor]];

float bwidth = ( 205 * coeffi)/ window. screen. Scale;

float bheight = ( coeffi)/ window. screen. Scale;

float bx = width-bwidth- ten;

float by = height-bheight- ten;

btnjump = [[UIButton alloc]initwithframe:cgrectmake(X+BX, Y+by, Bwidth, Bheight) ];

//btnjump.titlelabel.font=[uifont boldsystemfontofsize:15.0];

//[btnjump settitle:@ "Play" forstate:0];

//[btnjump setbackgroundimage:[uiimage imagenamed:@ "Yellow_middle_btn.png"] forstate:0];

[btnjumpsetbackgroundimage: [UIImageimagenamed:@ "Ui_button_new_ Tgjq0000.png "] forstate:uicontrolstatenormal];

[btnjumpsetbackgroundimage: [UIImageimagenamed:@ "Ui_button_new_ Tgjq0000_1.png "] forstate:uicontrolstatehighlighted];

[btnjumpaddtarget:self action:@selector(jumpover:) forControlEvents:uicontroleventtouchupinside];

// set Listener function

// Monitor whether the home key is triggered to suspend the program.

[[nsnotificationcenterdefaultcenter] addobserver:self selector: @selector(applicationsuspend:) Name:uiapplicationwillresignactivenotificationobject:nil];

// monitor whether to re-enter the program .

[[nsnotificationcenterdefaultcenter] addobserver:self selector: @selector(applicationresumed:) Name:uiapplicationdidbecomeactivenotificationobject:nil];

}

-(void) finished: (ID) Sender

{

//// After the end of the animation, remove the listening settings to prevent the second binding of the listening function when the crash occurred

[[nsnotificationcenterdefaultcenter] removeobserver:self];

[moviecontroller. Viewremovefromsuperview];

movieplayer, close();

[ self release];

}

-(void) Jumpover: (ID) Sender

{

[moviecontrollerstop];

}

-(void) play

{

//[view AddSubview:movieController.view];

//[view Sendsubviewtoback:view];

[windowaddsubview : moviecontroller. View];

[windowaddsubview : btnjump];

[windowmakekeyandvisible];

[moviecontrollerplay];

}

-(void) Dealloc

{

[moviecontrollerrelease];

[windowrelease];

[Super dealloc];

}

// used to call the following function before the program hangs when the Home key is clicked on the iPhone

-(void) Applicationsuspend: (nsnotification *) notification

{

[moviecontrollerpause];

}

// when the pending program re-enters the runtime, the following function is called

-(void) applicationresumed: (nsnotification *) notification

{

// re-play paused animations

[moviecontrollerplay];

}

@end

android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.