Hello,
I built an iPad app on Flash CS6 using air sdk 3.2. In the app, there is a button to play a video. I want it to play the video in native video player of iPad fullscreen.
I tried two methods :
1. navigateToURL() function. In this method, it first opens a web browser and then plays the video in separate native video player. I don't want it open a web browser first. Here is the code i used :
var req:URLRequest = new URLRequest(videoURL);
navigateToURL(req, "_self");
2. StageWebView component. In this method, clicking the button draws the video player on the app 100% size of the stage. But in the video player, there is fullscreen button. When you click it, it makes no change on the video player size but it changes the style of the video player (video scroller comes to top of the video, sound controller comes, etc.) So, this may make people confusing. Here is the code :
public var webView:StageWebView = new StageWebView();
webView.stage = this.stage;
webView.viewPort = new Rectangle( 0, 0, stage.width, stage.height);
webView.loadURL(videoURL);
I need a clear solution which opens a fullscreen native video player when i click the button. Please help me.
Thanks
Hi,
See the code below
--------------------------------------------
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
public class VideoImporter extends MovieClip
{
public var vid:Video = new Video();
public var netStreamObj:NetStream;
public static var instance:VideoImporter;
public static function getInstance():VideoImporter
{
if (instance == null)
{
instance = new VideoImporter();
}
return instance;
}
public function VideoImporter()
{
instance = this;
init();
}
private function init():void
{
vid.width = 1024;
vid.height = 768;
var nc:NetConnection = new NetConnection();
nc.connect( null );
netStreamObj = new NetStream( nc );
netStreamObj.bufferTime = 5;
netStreamObj.client = this;
netStreamObj.addEventListener( NetStatusEvent.NET_STATUS, onStatus );
}
private function onStatus( event:NetStatusEvent ):void
{
switch( event.info.code )
{
case "NetStream.Buffer.Empty":
//show buffering graphic
break;
case "NetStream.Buffer.Full":
//hide buffering graphic
break;
case "NetStream.Play.Stop":
netStreamObj.seek(0);
break;
}
}
public function onMetaData( info:Object ):void
{
trace( info );
}
public function onXMPData( info:Object ):void
{
trace( info );
}
public function playVideo(pathStr:String,targetMc:MovieClip):void
{
targetMc.addChild(vid);
netStreamObj.play(pathStr);
vid.attachNetStream(netStreamObj);
}
}
}
You can use this class for importing your video in iPad, just call the playVideo method in your class, parameters are pathStr: path of your video file in your project and targetMc : movieclip in which you want to show your video. In the above class video size is 1024 X 768, as per ipad resolution, if you want to some other resolution, you can change that accordingly.
Please be sure about the video format, it only plays .FLV and .MP4 formats.
I'm using this calss in my project and this is working perfectly, If any error occurs, I'm open for that.
Regards,
Vipul
North America
Europe, Middle East and Africa
Asia Pacific