cocos2d-x IOS 和Android播放视频(包括网络视频)

cocos2d-x IOS 和Android播放视频(包括网络视频),第1张

概述一. 播放本地视频      对于iOS平台的视频播放,我们可以借助Cocos2d-iphone 的Extensions:CCVideoPlayer来实现     1.导入支持cocos2d-x的扩展库到项目中(这里可以参考Himi的第六章视频播放小节内容,这里的扩展库是Himi修改好的,我就直接拿来用了!希望没有侵权!)     2.添加MediaPalyer框架到项目中     3.修改ios 一.播放本地视频

对于iOS平台的视频播放,我们可以借助Cocos2d-iphone 的Extensions:CCVIDeoPlayer来实现

1.导入支持cocos2d-x的扩展库到项目中(这里可以参考Himi的第六章视频播放小节内容,这里的扩展库是Himi修改好的,我就直接拿来用了!希望没有侵权!)

2.添加MediaPalyer框架到项目中

3.修改ios里AppController.h 和AppController.mm文件

AppController.h

[plain] view plain copy #import"../Classes/CCVIDeoPlayeriOS/CCVIDeoPlayer.h" @classRootVIEwController; @interfaceAppController:NSObject<UIAccelerometerDelegate,UIAlertVIEwDelegate, UITextFIEldDelegate,UIApplicationDelegate,CCVIDeoPlayerDelegate> { UIWindow*window; RootVIEwController*vIEwController; } @property(nonatomic,retain)UIWindow*window; @property(nonatomic,retain)RootVIEwController*vIEwController; -(voID)playVIDeo; @end

AppController.mm

添加using namespace cocos2d;

因为playVIDeo用到了cocos2d-x里的API

CCSizesize = CCDirector::sharedDirector()->getWinSize();

在application函数里添加视频播放监听

[CCVIDeoPlayer setDelegate :self];

playVIDeo实现如下:

copy -(voID)playVIDeo { CCSizesize=CCDirector::sharedDirector()->getWinSize(); [CCVIDeoPlayersetScrrenSize:CGSizeMake(size.wIDth-400,size.height-300)]; [CCVIDeoPlayersetNoSkip:true]; [CCVIDeoPlayerplayMovIEWithfile:@"xcm.mp4"]; //播放网络视频 //[vIEwControllerplayURLVIDeo]; }

4.添加混编类IOSPlayVIDeo

IOSPlayVIDeo.h

copy #ifndef__IOSPlayVIDeo_SCENE_H__ #define__IOSPlayVIDeo_SCENE_H__ classIOSPlayVIDeo public: staticvoidplayVIDeoForIOS(); }; #endif//__IOSPlayVIDeo_SCENE_H__

IOSPlayVIDeo.mm

copy #include"IOSPlayVIDeo.h" #include"AppController.h" voidioSPlayVIDeo::playVIDeoForIOS() AppController*app=(AppController*)[[UIApplicationsharedApplication]delegate]; [appplayVIDeo]; }

5.添加一个cocos2d-x类 :Platform

Platform.h

copy #ifndef__Platform_SCENE_H__ #define__Platform_SCENE_H__ #include"cocos2d.h" usingnamespacecocos2d; classplatform public: staticvoidplayVIDeo();//用于播放本地视频 staticvoidplayURLVIDeo();//用于播放网络视频 }; #endif//__Platform_SCENE_H__


Platform.mm

copy #include"Platform.h" #include"../cocos2dx/platform/CCPlatformConfig.h" #if(CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID) #include<jni.h> #include"../cocos2dx/platform/androID/jni/JniHelper.h" #include<androID/log.h> #elif(CC_TARGET_PLATFORM==CC_PLATFORM_IOS) #include"IOSPlayVIDeo.h" #endif voidplatform::playVIDeo() //AndroID播放本地视频 JniMethodInfominfo; boolisHave=JniHelper::getmethodInfo(minfo,"org/cocos2dx/playvIDeo/playvIDeo","playVedio","()V"); if(isHave) minfo.env->CallStaticVoIDMethod(minfo.classID,minfo.methodID); //IOS播放本地视频 IOSPlayVIDeo::playVIDeoForIOS(); #endif } voidplatform::playURLVIDeo() //AndroID播放网络视频 //IOS播放网络视频 }

IOS项目里只需在需要的地方调用函数就可以播放视频了!

至于Android就稍微麻烦一点,需要用到Jni 技术,C++调用Java

A.修改playvIDeo.java

修改后如下:

@H_888_404@ [java] copy packageorg.cocos2dx.playvIDeo; importorg.cocos2dx.lib.Cocos2dxActivity; importorg.cocos2dx.lib.Cocos2dxEditText; importorg.cocos2dx.lib.Cocos2dxGLSurfaceVIEw; importorg.cocos2dx.lib.Cocos2dxRenderer; importandroID.app.ActivityManager; importandroID.content.Context; importandroID.content.Intent; importandroID.content.pm.ConfigurationInfo; importandroID.os.Bundle; importandroID.util.Log; importandroID.vIEw.VIEwGroup; importandroID.Widget.FrameLayout; publicclassplayvIDeoextendsCocos2dxActivity{ //当前类实例 publicstaticplayvIDeoinstance; //用于切换Activity publicstaticIntentintent; protectedvoIDonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); instance=this; if(detectopenGLES20()){ //getthepackagename,it'susedtosettheresourcepath Stringpackagename=getApplication().getPackagename(); super.setPackagename(packagename); //FrameLayout VIEwGroup.LayoutParamsframelayout_params= newVIEwGroup.LayoutParams(VIEwGroup.LayoutParams.FILL_PARENT, VIEwGroup.LayoutParams.FILL_PARENT); FrameLayoutframelayout=newFrameLayout(this); framelayout.setLayoutParams(framelayout_params); //Cocos2dxEditTextlayout VIEwGroup.LayoutParamsedittext_layout_params= newVIEwGroup.LayoutParams(VIEwGroup.LayoutParams.FILL_PARENT, VIEwGroup.LayoutParams.WRAP_CONTENT); Cocos2dxEditTextedittext=newCocos2dxEditText(this); edittext.setLayoutParams(edittext_layout_params); //...addtoFrameLayout framelayout.addVIEw(edittext); //Cocos2dxGLSurfaceVIEw mGLVIEw=newCocos2dxGLSurfaceVIEw(this); framelayout.addVIEw(mGLVIEw); mGLVIEw.setEGLContextClIEntVersion(2); mGLVIEw.setCocos2dxRenderer(newCocos2dxRenderer()); mGLVIEw.setTextFIEld(edittext); //SetframelayoutasthecontentvIEw setContentVIEw(framelayout); intent=newIntent(playvIDeo.this,VedioActivity.class); else{ Log.d("activity","don'tsupportgles2.0"); finish(); voIDplayVIDeo() instance.startActivity(intent); @OverrIDe protectedvoIDonPause(){ super.onPause(); mGLVIEw.onPause(); protectedvoIDonResume(){ super.onResume(); mGLVIEw.onResume(); privatebooleandetectopenGLES20() ActivityManageram= (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); ConfigurationInfoinfo=am.getDeviceConfigurationInfo(); return(info.reqGlEsversion>=0x20000); static{ System.loadlibrary("game"); } 添加两个.java文件:VIDeoVIEw.java和VedioActivity.java

VIDeoVIEw.java

copy importjava.io.IOException; importandroID.media.AudioManager; importandroID.media.MediaPlayer; importandroID.media.MediaPlayer.OnCompletionListener; importandroID.media.MediaPlayer.OnErrorListener; importandroID.net.Uri; importandroID.util.AttributeSet; importandroID.vIEw.KeyEvent; importandroID.vIEw.MotionEvent; importandroID.vIEw.SurfaceHolder; importandroID.vIEw.SurfaceHolder.Callback; importandroID.vIEw.SurfaceVIEw; importandroID.vIEw.VIEw; importandroID.vIEw.VIEwGroup.LayoutParams; importandroID.Widget.MediaController; importandroID.Widget.MediaController.MediaPlayerControl; publicclassVIDeoVIEwextendsSurfaceVIEwimplementsMediaPlayerControl,Callback{ privateContextmContext; //settablebytheclIEnt privateUrimUri; privateintmDuration; //AllthestuffweneedforplayingandshowingavIDeo privateSurfaceHoldermSurfaceHolder=null; privateMediaPlayermMediaPlayer=null; privatebooleanmIsPrepared; privateintmVIDeoWIDth; privateintmVIDeoHeight; privateintmSurfaceWIDth; privateintmSurfaceHeight; privateMediaControllermMediaController; privateOnCompletionListenermOnCompletionListener; privateMediaPlayer.OnPreparedListenermOnPreparedListener; privateintmCurrentBufferPercentage; privateOnErrorListenermOnErrorListener; privatebooleanmStartWhenPrepared; privateintmSeekWhenPrepared; privateMySizeChangelinstenermMyChangelinstener; publicintgetVIDeoWIDth(){ returnmVIDeoWIDth; publicintgetVIDeoHeight(){ returnmVIDeoHeight; publicvoIDsetVIDeoScale(intwIDth,intheight){ LayoutParamslp=getLayoutParams(); lp.height=height; lp.wIDth=wIDth; setLayoutParams(lp); publicinterfaceMySizeChangelinstener{ publicvoIDdoMyThings(); publicvoIDsetMySizeChangelinstener(MySizeChangelinstenerl){ mMyChangelinstener=l; publicVIDeoVIEw(Contextcontext){ super(context); mContext=context; initVIDeoVIEw(); publicVIDeoVIEw(Contextcontext,AttributeSetattrs){ this(context,attrs,0); intdefStyle){ super(context,defStyle); @OverrIDe protectedvoIDonMeasure(intwIDthMeasureSpec,intheightmeasureSpec){ //Log.i("@@@@","onMeasure"); intwIDth=getDefaultSize(mVIDeoWIDth,wIDthMeasureSpec); intheight=getDefaultSize(mVIDeoHeight,heightmeasureSpec); /* *if(mVIDeoWIDth>0&&mVIDeoHeight>0){if(mVIDeoWIDth*height *>wIDth*mVIDeoHeight){//Log.i("@@@",108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> *"imagetootall,correcting");height=wIDth*mVIDeoHeight/ *mVIDeoWIDth;}elseif(mVIDeoWIDth*height<wIDth*mVIDeoHeight *){//Log.i("@@@","imagetoowIDe,correcting");wIDth=height* *mVIDeoWIDth/mVIDeoHeight;}else{//Log.i("@@@",108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> *"aspectratioiscorrect:"+//wIDth+"/"+height+"="+ *//mVIDeoWIDth+"/"+mVIDeoHeight);}} */ //Log.i("@@@@@@@@@@","settingsize:"+wIDth+'x'+height); setMeasuredDimension(wIDth,height); publicintresolveAdjustedSize(intdesiredSize,intmeasureSpec){ intresult=desiredSize; intspecMode=MeasureSpec.getMode(measureSpec); intspecsize=MeasureSpec.getSize(measureSpec); switch(specMode){ caseMeasureSpec.UnspecIFIED: /* *Parentsayswecanbeasbigaswewant.Justdon'tbelarger *thanmaxsizeimposedonourselves. */ result=desiredSize; break; caseMeasureSpec.AT_MOST: *Parentsayswecanbeasbigaswewant,uptospecsize.Don'tbe *largerthanspecSize,anddon'tbelargerthanthemaxsize *imposedonourselves. result=Math.min(desiredSize,specsize); break; caseMeasureSpec.EXACTLY: //Nochoice.Dowhatwearetold. result=specsize; returnresult; privatevoIDinitVIDeoVIEw(){ mVIDeoWIDth=0; mVIDeoHeight=0; getHolder().addCallback(this); getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setFocusable(true); setFocusableIntouchMode(true); requestFocus(); publicvoIDsetVIDeoPath(Stringpath){ setVIDeoURI(Uri.parse(path)); publicvoIDsetVIDeoURI(Uriuri){ mUri=uri; mStartWhenPrepared=false; mSeekWhenPrepared=0; openVIDeo(); requestLayout(); invalIDate(); publicvoIDstopPlayback(){ if(mMediaPlayer!=null){ mMediaPlayer.stop(); mMediaPlayer.release(); mMediaPlayer=null; privatevoIDopenVIDeo(){ if(mUri==null||mSurfaceHolder==null){ //notreadyforplaybackjustyet,willtryagainlater return; //Tellthemusicplaybackservicetopause //Todo:theseconstantsneedtobepublishedsomewhereinthe //framework. Intenti=newIntent("com.androID.music.musicservicecommand"); i.putExtra("command","pause"); mContext.sendbroadcast(i); if(mMediaPlayer!=null){ mMediaPlayer.reset(); mMediaPlayer.release(); mMediaPlayer=null; try{ mMediaPlayer=newMediaPlayer(); mMediaPlayer.setonPreparedListener(mPreparedListener); mMediaPlayer.setonVIDeoSizeChangedListener(mSizeChangedListener); mIsPrepared=false; //Log.v(TAG,"resetdurationto-1inopenVIDeo"); mDuration=-1; mMediaPlayer.setonCompletionListener(mCompletionListener); mMediaPlayer.setonErrorListener(mErrorListener); mMediaPlayer.setonBufferingUpdateListener(mBufferingUpdateListener); mCurrentBufferPercentage=0; mMediaPlayer.setDataSource(mContext,mUri); mMediaPlayer.setdisplay(mSurfaceHolder); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.setScreenOnWhilePlaying(true); mMediaPlayer.prepareAsync(); attachMediaController(); }catch(IOExceptionex){ //Log.w(TAG,"Unabletoopencontent:"+mUri,ex); return; }catch(IllegalArgumentExceptionex){ //Log.w(TAG,ex); publicvoIDsetMediaController(MediaControllercontroller){ if(mMediaController!=null){ mMediaController.hIDe(); mMediaController=controller; attachMediaController(); privatevoIDattachMediaController(){ if(mMediaPlayer!=null&&mMediaController!=null){ mMediaController.setMediaPlayer(this); VIEwanchorVIEw=this.getParent()instanceofVIEw?(VIEw)this .getParent():this; mMediaController.setAnchorVIEw(anchorVIEw); mMediaController.setEnabled(mIsPrepared); MediaPlayer.OnVIDeoSizeChangedListenermSizeChangedListener=newMediaPlayer.OnVIDeoSizeChangedListener(){ publicvoIDonVIDeoSizeChanged(MediaPlayermp,intwIDth,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> mVIDeoWIDth=mp.getVIDeoWIDth(); mVIDeoHeight=mp.getVIDeoHeight(); if(mMyChangelinstener!=null){ mMyChangelinstener.doMyThings(); if(mVIDeoWIDth!=0&&mVIDeoHeight!=0){ getHolder().setFixedSize(mVIDeoWIDth,mVIDeoHeight); MediaPlayer.OnPreparedListenermPreparedListener=newMediaPlayer.OnPreparedListener(){ publicvoIDonPrepared(MediaPlayermp){ //brIEflyshowthemediacontroller mIsPrepared=true; if(mOnPreparedListener!=null){ mOnPreparedListener.onPrepared(mMediaPlayer); if(mMediaController!=null){ mMediaController.setEnabled(true); mVIDeoWIDth=mp.getVIDeoWIDth(); mVIDeoHeight=mp.getVIDeoHeight(); //mVIDeoHeight); if(mSurfaceWIDth==mVIDeoWIDth &&mSurfaceHeight==mVIDeoHeight){ //WedIDn'tactuallychangethesize(itwasalreadyatthe //size //weneed),sowewon'tgeta"surfacechanged"callback, //so //startthevIDeohereinsteadofinthecallback. if(mSeekWhenPrepared!=0){ mMediaPlayer.seekTo(mSeekWhenPrepared); mSeekWhenPrepared=0; if(mStartWhenPrepared){ mMediaPlayer.start(); mMediaController.show(); }elseif(!isPlaying() &&(mSeekWhenPrepared!=0||getCurrentposition()>0)){ //Showthemediacontrolswhenwe'repausedintoa //vIDeoandmake'emstick. mMediaController.show(0); }else{ //Wedon'tkNowthevIDeosizeyet,butshouldstartanyway. //ThevIDeosizemightbereportedtouslater. privateMediaPlayer.OnCompletionListenermCompletionListener=newMediaPlayer.OnCompletionListener(){ publicvoIDonCompletion(MediaPlayermp){ mMediaController.hIDe(); if(mOnCompletionListener!=null){ mOnCompletionListener.onCompletion(mMediaPlayer); privateMediaPlayer.OnErrorListenermErrorListener=newMediaPlayer.OnErrorListener(){ publicbooleanonError(MediaPlayermp,intframework_err,intimpl_err){ //Log.d(TAG,"Error:"+framework_err+","+impl_err); /*IfanerrorhandlerhasbeensupplIEd,useitandfinish.*/ if(mOnErrorListener!=null){ if(mOnErrorListener.onError(mMediaPlayer,framework_err,248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> impl_err)){ returntrue; *Otherwise,popupanerrordialogsotheuserkNowsthat *somethingbadhashappened.Onlytryandpopupthedialogif *we'reattachedtoawindow.Whenwe'regoingawayandnolonger *haveawindow,don'tbothershowingtheuseranerror. if(getwindowToken()!=null){ *if(framework_err== *MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK){ *messageID=com.androID.internal.R.string. *VIDeoVIEw_error_text_invalID_progressive_playback;}else{ *messageID= *com.androID.internal.R.string.VIDeoVIEw_error_text_unkNown;} * *newAlertDialog.Builder(mContext) *.setTitle(com.androID.internal *.R.string.VIDeoVIEw_error_Title).setMessage(messageID) *.setPositivebutton *(com.androID.internal.R.string.VIDeoVIEw_error_button,new *DialogInterface.OnClickListener(){publicvoID *onClick(DialogInterfacedialog,intwhichbutton){Ifweget *here,thereisnoonErrorListener,soatleastinformthem *thatthevIDeoisover. *if(mOnCompletionListener!=null){ *mOnCompletionListener.onCompletion(mMediaPlayer);}}}) *.setCancelable(false).show(); returntrue; privateMediaPlayer.OnBufferingUpdateListenermBufferingUpdateListener=newMediaPlayer.OnBufferingUpdateListener(){ publicvoIDonBufferingUpdate(MediaPlayermp,intpercent){ mCurrentBufferPercentage=percent; /** *RegisteracallbacktobeinvokeDWhenthemediafileisloadedandready *togo. * *@paraml *Thecallbackthatwillberun publicvoIDsetonPreparedListener(MediaPlayer.OnPreparedListenerl){ mOnPreparedListener=l; /** *RegisteracallbacktobeinvokeDWhentheendofamediafilehasbeen *reachedduringplayback. *@paraml *Thecallbackthatwillberun publicvoIDsetonCompletionListener(OnCompletionListenerl){ mOnCompletionListener=l; *RegisteracallbacktobeinvokeDWhenanerroroccursduringplaybackor *setup.IfnoListenerisspecifIEd,oriftheListenerreturnedfalse,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> *VIDeoVIEwwillinformtheuserofanyerrors. publicvoIDsetonErrorListener(OnErrorListenerl){ mOnErrorListener=l; publicbooleanontouchEvent(MotionEventev){ if(mIsPrepared&&mMediaPlayer!=null&&mMediaController!=null){ toggleMediaControlsVisiblity(); returnfalse; publicbooleanontrackballEvent(MotionEventev){ publicbooleanonKeyDown(intkeyCode,KeyEventevent){ if(mIsPrepared&&keyCode!=KeyEvent.KEYCODE_BACK &&keyCode!=KeyEvent.KEYCODE_VolUME_UP &&keyCode!=KeyEvent.KEYCODE_VolUME_DOWN &&keyCode!=KeyEvent.KEYCODE_MENU &&keyCode!=KeyEvent.KEYCODE_CALL &&keyCode!=KeyEvent.KEYCODE_ENDCALL&&mMediaPlayer!=null &&mMediaController!=null){ if(keyCode==KeyEvent.KEYCODE_headSETHOOK ||keyCode==KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE){ if(mMediaPlayer.isPlaying()){ pause(); start(); }elseif(keyCode==KeyEvent.KEYCODE_MEDIA_Stop &&mMediaPlayer.isPlaying()){ pause(); mMediaController.show(); }else{ toggleMediaControlsVisiblity(); returnsuper.onKeyDown(keyCode,event); privatevoIDtoggleMediaControlsVisiblity(){ if(mMediaController.isShowing()){ publicvoIDstart(){ if(mMediaPlayer!=null&&mIsPrepared){ mMediaPlayer.start(); mStartWhenPrepared=false; mStartWhenPrepared=true; publicvoIDpause(){ if(mMediaPlayer!=null&&mIsPrepared){ if(mMediaPlayer.isPlaying()){ mMediaPlayer.pause(); publicintgetDuration(){ if(mDuration>0){ returnmDuration; mDuration=mMediaPlayer.getDuration(); returnmDuration; publicintgetCurrentposition(){ returnmMediaPlayer.getCurrentposition(); return0; publicvoIDseekTo(intmsec){ mMediaPlayer.seekTo(msec); mSeekWhenPrepared=msec; publicbooleanisPlaying(){ returnmMediaPlayer.isPlaying(); returnfalse; publicintgetBufferPercentage(){ returnmCurrentBufferPercentage; publicvoIDsurfaceChanged(SurfaceHolderholder,intformat,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> intheight){ mSurfaceWIDth=wIDth; mSurfaceHeight=height; if(mMediaPlayer!=null&&mIsPrepared&&mVIDeoWIDth==wIDth &&mVIDeoHeight==height){ if(mSeekWhenPrepared!=0){ mMediaPlayer.seekTo(mSeekWhenPrepared); publicvoIDsurfaceCreated(SurfaceHolderholder){ mSurfaceHolder=holder; publicvoIDsurfaceDestroyed(SurfaceHolderholder){ //afterwereturnfromthiswecan'tusethesurfaceanymore mSurfaceHolder=null; if(mMediaController!=null) mMediaPlayer.reset(); publicbooleancanPause(){ //Todoauto-generatedmethodstub publicbooleancanSeekBackward(){ //Todoauto-generatedmethodstub publicbooleancanSeekForward(){ } VedioActivity.java

copy importandroID.app.Activity; importandroID.vIEw.Window; importandroID.vIEw.WindowManager; publicclassVedioActivityextendsActivityimplementsMediaPlayer.OnCompletionListener{ //隐藏标题栏 this.requestwindowFeature(Window.FEATURE_NO_Title); //隐藏状态栏 this.getwindow().setFlags(WindowManager.LayoutParams.FLAG_FulLSCREEN,WindowManager.LayoutParams.FLAG_FulLSCREEN); //初始化视频VIEw VIDeoVIEwvIEw=newVIDeoVIEw(this); //设置显示视频VIEw setContentVIEw(vIEw); //注册监听视频 vIEw.setonCompletionListener(this); //设置视频文件路径 vIEw.setVIDeoURI(Uri.parse("androID.resource://org.cocos2dx.playvIDeo/"+R.raw.xcm)); //播放视频 vIEw.start(); //当视频播放完后回调此函数 //结束当前Activity this.finish(); } 注:在 res下新建一个名为raw的文件夹,将assets下xcm.mp4拷贝到raw文件夹下,否则 :raw 和xcm无法识别!!!

二.播放网络视频

IOS项目:

在RootVIEwController.h里添加playURLVIDeo函数

并导入头文件#import"MediaPlayer/MediaPlayer.h"

RootVIEwController.mm实现playURLVIDeo函数如下:

copy -(voID)playURLVIDeo NSURL*movIEUrl=[NSURLURLWithString:@"http://v.youku.com/player/getRealM3U8/vID/XMzU5NDE3NTYw/type//vIDeo.m3u8"]; MPMovIEPlayerVIEwController*player=[[MPMovIEPlayerVIEwControlleralloc]initWithContentURL:movIEUrl]; [selfpresentMovIEPlayerVIEwControllerAnimated:player]; }

然后修改AppController.mm里的函数

copy //CCSizesize=CCDirector::sharedDirector()->getWinSize(); //[CCVIDeoPlayersetScrrenSize:CGSizeMake(size.wIDth-400,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> //[CCVIDeoPlayersetNoSkip:true]; //[CCVIDeoPlayerplayMovIEWithfile:@"xcm.mp4"]; [vIEwControllerplayURLVIDeo]; }

AndroID项目:修改playvIDeo.java

修改后如下:

copy importandroID.content.Intent; publicclassplayvIDeoextendsCocos2dxActivity{ //当前类实例 publicstaticplayvIDeoinstance; //用于切换Activity publicstaticIntentintent; publicvoIDonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); voIDplayURLVIDeo() Intentintent=newIntent(Intent.ACTION_VIEW); Stringtype="vIDeo/*"; Uriuri=Uri.parse("http://forum.ea3w.com/coll_ea3w/attach/2008_10/12237832415.3gp"); intent.setDataAndType(uri,type); instance.startActivity(intent); } 总结

以上是内存溢出为你收集整理的cocos2d-x IOS 和Android播放视频(包括网络视频)全部内容,希望文章能够帮你解决cocos2d-x IOS 和Android播放视频(包括网络视频)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1081333.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存