12-18-2010 03:28 PM
I use as3 to create an flv player . The code work just fine in desktop app but in simulator the flv file can not loaded ! I have tried so many way ( i have turned 3d gracphic on ) . Does anyone know why ? BTW this is my entire code :
package
{
import flash.display.Sprite;
import flash.events.*;
import flash.events.MouseEvent;
import flash.filesystem.File;
import flash.media.Video;
import flash.net.FileFilter;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.text.TextField;
import flash.text.TextFormat;
import qnx.ui.buttons.Button;
import qnx.ui.buttons.LabelButton;
public class TabletOSVideoDemo extends Sprite
{
public function TabletOSVideoDemo()
{
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
function asyncErrorHandler(event:AsyncErrorEvent):void
{
// ignore error
}
var vid:Video = new Video();
vid.attachNetStream(ns);
ns.play("C:\lastChristmas.flv");
addChild(vid);
var myFormat:TextFormat = new TextFormat();
myFormat.color = 0xAA0000;
myFormat.size = 24;
myFormat.italic = true;
var textClose:TextField = new TextField();
textClose.text = "X";
textClose.setTextFormat(myFormat);
var closeButton:Button = new Button();
closeButton.addChild(textClose);
closeButton.addEventListener(MouseEvent.CLICK, closeHandler);
closeButton.width = 50;
closeButton.x = 0
closeButton.y = 0
addChild(closeButton);
function closeHandler(event:MouseEvent):void{
stage.nativeWindow.close();
}
}
}
}
12-18-2010 03:34 PM
hey,
im not too familar with the video API's (ive heard its buggy here and there) but from the look of your code, you are not properly referencing the FLV file:
ns.play("C:\lastChristmas.flv");
Are you packaging your video file with your application (BAR file)? If so assuming its in the same directory as your main .as file change the above code to the following and give it a shot:
ns.play(File.applicationDirectory.nativePath + "/lastChristmas.flv");
hope that helps. good luck!
12-19-2010 01:11 AM
i have tried your code ( i did put lastChristmas.flv in the same folder of my app) but the problem still there . I wonder if lastChristmas.flv must be in the hard disk of the simulator ? i have configure to share my local folder with simulator but its useless . Anyone help me ?
12-19-2010 05:17 AM
hey,
what are you using to compile and package your application?
12-19-2010 06:23 AM
i use Flash Builder 4.5 trial version . what do u mean by package ? i just create an action script mobie project and choose flex hero to compile , i just do just like the tutorial to set up enviroment
12-19-2010 08:06 AM
hey,
ah ok. i was just checking. you dont need to share any folders. whenever you place any items below your 'src' folder in Flash Builder it automatically packages the files in with your application and puts it on the device in the applicationDirectory folder. And packaging is what happens after flash builder compiles your application. so the file is there but its not playing properly. ill look into it further.
12-19-2010 08:36 AM
hey,
back with an update. seems as though it was throwing errors such as a reference error. try the following updated code and let me know if it works for you:
package
{
import flash.display.Sprite;
import flash.events.*;
import flash.events.MouseEvent;
import flash.filesystem.File;
import flash.media.Video;
import flash.net.FileFilter;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.text.TextField;
import flash.text.TextFormat;
import qnx.ui.buttons.Button;
import qnx.ui.buttons.LabelButton;
public class TabletOSVideoDemo extends Sprite
{
public function TabletOSVideoDemo()
{
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
function asyncErrorHandler(event:AsyncErrorEvent):void
{
// ignore error
}
var vid:Video = new Video();
vid.attachNetStream(ns);
ns.client = new Object();
ns.play("lastChristmas.flv");
addChild(vid);
var myFormat:TextFormat = new TextFormat();
myFormat.color = 0xAA0000;
myFormat.size = 24;
myFormat.italic = true;
var textClose:TextField = new TextField();
textClose.text = "X";
textClose.setTextFormat(myFormat);
var closeButton:Button = new Button();
closeButton.addChild(textClose);
closeButton.addEventListener(MouseEvent.CLICK, closeHandler);
closeButton.width = 50;
closeButton.x = 0
closeButton.y = 0
addChild(closeButton);
function closeHandler(event:MouseEvent):void{
stage.nativeWindow.close();
}
}
}
}
the two lines i modified are the bolded lines in the code. i added the client property to prevent the application from throwing a reference errror. you should probably handle it better though in your finall application. heres a link for more details on how to:
http://www.adobe.com/devnet/flash/quickstart/metad
also when writing the file path, just use the filename.flv since its under your srce directory. if it was under another directory under your source it would just be "folder/lastChristmas.flv".
on a side not though when i loaded up the video it worked half way but then it stopped. it might be because of the buggy video playback on the device simulator. but the video loads and works. hope that helps! good luck!
12-19-2010 09:14 AM
thanks for your help but it didnt work , how sad i am ! btw , if i replace ns.play("lastChristmas.flv") with ns.play("http://ww.helpexamples.com/flash/video/cuepoints.f
12-19-2010 09:18 AM
hey,
the reason why its only 4 seconds and not the entire video is because video playback is not fully supported in the simulator. last time i heard it was still being worked on. make sure that you are spelling the name of the flv file and the location is in fact under the src directroy and not under any other folder in your project. one way to confirm is by going to the bin-debug folder and if you see that your lastChristmas.flv file is there and not under any sub directories then its placed in the right place.
i didnt quite understand what you meant by this line: "you should add 1 more w at the url , because the i cant post a link here"
12-19-2010 12:01 PM