playing video works on simulator but not on ipad (2) - apache-flex

I have been trying to play a video that was converted using http://www.mirovideoconverter.com/ to mp4 file , it is woking fine on the simulator but on the ipad i don't see the video.
How can I fix??
attaching Video code :
package com.view.generic
{
import com.constants.Dimentions;
import com.view.AbstractScreen;
import com.view.IScreen;
import com.view.gui.Btn;
import flash.errors.IOError;
import flash.events.IOErrorEvent;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import org.osflash.signals.natives.NativeSignal;
public class VideoMode extends AbstractScreen implements IScreen
{
private var _player:Video;
private var _stream:NetStream;
public function VideoMode()
{
}
override public function start():void{
super.start();
var conn:NetConnection = new NetConnection();
conn.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler)
conn.addEventListener(IOErrorEvent.NETWORK_ERROR, netStatusError)
conn.connect(null);
layoutPlayer();
layoutMenu();
}
override public function stop():void{
_stream.pause();
}
private function layoutMenu():void{
var playBtn:Btn = new Btn("video_play_button.png");
addChild(playBtn);
playBtn.x = (Dimentions.HEIGHT -playBtn.width)/2;
playBtn.y = _player.y+_player.height+20;
var clickSignal:NativeSignal = new NativeSignal(playBtn,MouseEvent.CLICK);
clickSignal.add(play);
var fullScrBtn:Btn = new Btn("full_screen.png");
addChild(fullScrBtn);
fullScrBtn.x = _player.width -fullScrBtn.width+_player.x;;
fullScrBtn.y = _player.y+_player.height+20;
var fullScrSignal:NativeSignal = new NativeSignal(fullScrBtn,MouseEvent.CLICK);
fullScrSignal.add(goFullScreen);
}
private function layoutPlayer():void{
_player.width = 400;
_player.height = 300;
_player.x = (Dimentions.HEIGHT -_player.width)/2;
_player.y = 200;
_stream.play("../../../assets/drum_ny.flv");
_stream.pause();
}
private function goFullScreen(e:MouseEvent):void{
if(_player.x == 0){
layoutPlayer()
}else{
_player.x = 0;
_player.y = 0;
_player.width = stage.fullScreenWidth;
_player.height = stage.fullScreenHeight;
}
}
private function play(e:MouseEvent):void{
_stream.resume()
}
private function netStatusHandler(e:NetStatusEvent):void{
if(e.info.code=="NetConnection.Connect.Success"){
_stream = new NetStream(NetConnection(e.target));
_stream.client = this;
_player = new Video();
addChild(_player);
_player.attachNetStream(_stream)
}
}
private function netStatusError(e:IOError):void{
trace(e)
}
override public function destroy():void{
}
public function onMetaData(info:Object):void {
}
}
}
Thank you!

This is likely your problem :
_stream.play("../../../assets/drum_ny.flv");
That file doesn't exist once you compile your app into a .ipa file. Try changing that to a web address of somewhere you can upload it to and if it works, then that's your prob.

The issue was resolved by replacing the FLV file, however I am still not sure why one flv file works and the other does not.
If you encounter such a problem (video works on simulator but not on device) your first bet should be replacing the video source.

Related

How I get real time statistics in MOEA Framework?

I know there is the Instrumenter class, however this method outputs the data after the run finish. I would like to get (near) real-time data, like in the Symbolic Regression in the Demos.
Looking at its code, it seems I need to use the step method and try to imitate the runSingleSeed in Executor. Is there a better way? Some other class like Instrumenter but asynchronous. I cannot really find something similar online.
Just build a wrapper around the cycle (similar to the next one) and make it also a subject in an observer pattern.
import java.util.Properties;
import java.util.Arrays;
import java.text.DecimalFormat;
import org.moeaframework.core.Algorithm;
import org.moeaframework.core.Solution;
import org.moeaframework.core.Problem;
import org.moeaframework.core.Population;
import org.moeaframework.core.NondominatedPopulation;
import org.moeaframework.core.variable.EncodingUtils;
import org.moeaframework.core.spi.AlgorithmFactory;
import org.moeaframework.problem.misc.Kursawe;
public class Main{
public static void main(String[] args){
String algorithmName = "NSGAII";
Properties properties = new Properties();
properties.setProperty("populationSize", "100"); // to change properties
Problem problem = new Kursawe();
Algorithm algorithm = AlgorithmFactory.getInstance()
.getAlgorithm(algorithmName, properties, problem);
int maxGenerations = 100;
int generation = 0;
while( generation < maxGenerations ){
if( generation % 10 == 1 ){
System.out.println("Generation " + generation);
NondominatedPopulation paretoFront = algorithm.getResult();
// metrics
System.out.print("One of the pareto front: ");
System.out.println(toString(paretoFront.get(0)));
}
algorithm.step();
generation++;
}
algorithm.terminate();
System.out.println("Parento Front:");
for(Solution solution: algorithm.getResult()){
System.out.println(toString(solution));
}
export(algorithm.getResult());
}
private static String toString(Solution solution){
StringBuilder out = new StringBuilder();
double[] variables = EncodingUtils.getReal(solution);
double[] objectives = solution.getObjectives();
out.append("f");
out.append(doubleArrayToString(variables));
out.append(" = ");
out.append(doubleArrayToString(objectives));
return out.toString();
}
private static String doubleArrayToString(double[] array){
DecimalFormat format = new DecimalFormat("+#,##0.00;-#");
StringBuilder out = new StringBuilder();
out.append("[");
for(int i = 0; i < array.length-1; i++){
out.append(format.format(array[i]));
out.append(", ");
}
out.append(format.format(array[array.length-1]));
out.append("]");
return out.toString();
}
private static void export(Population population){
System.out.println();
for(Solution solution: population){
double[] objectives = solution.getObjectives();
System.out.println(String.format("%.3f,%.3f", objectives[0], objectives[1]));
}
}
}
Another option for the one indicated by Black Arrow, if you are using multithread, is to extentend AlgorithmFactory. For example:
public class MyAlgorithmFactory extends AlgorithmFactory {
private static Algorithm algorithm;
public Algorithm getGeneratedAlgorithm() {
return this.algorithm;
}
#Override
public Algorithm getAlgorithm(String name, Properties properties, Problem problem){
this.algorithm = super.getAlgorithm(name, properties, problem);
return algorithm;
}
}
Then you use this Factory on your Executor, for example:
MyAlgorithmFactory af = new MyAlgorithmFactory();
Executor executor = new Executor()
.usingAlgorithmFactory(af)
.withAlgorithm("NSGAII") //
.withProblem(yourProblemHere) //
.withMaxEvaluations(10000);
After this you can start the Executor on a separated thread, and call af.getGeneratedAlgorithm() to get the instance of Algorithm initialized by the Executor. From this Algorithm you can get, while the Executor is still running, the actual NondominatedPopulation to calc statistics.

Parse custom rss tags using Rome API

I am trying to use Rome for parsing some rss feeds. One of the rss feeds says
specifies 0.91 as the version and no custom xml namespace is defined but the entries still have a custom element in them. Can I use Rome to parse such custom tags without any defined namespace?
Thanks.
Yes. You need to write a custom parser to do it.
Let's say you want to handle the elements customString and customDate. Start by extending the Item class to store the custom elements.
package com.example;
import com.sun.syndication.feed.rss.Item;
import java.util.Date;
public class CustomItem extends Item {
private String _customString;
private Date _customDate;
public String getCustomString() {
return _customString;
}
public void setCustomString(String customString) {
_customString = customString;
}
public Date getCustomDate() {
return _customDate;
}
public void setCustomDate(Date customDate) {
_customDate = customDate;
}
}
Then write the parser. You also need to handle any standard elements you want to parse.
package com.example;
import com.example.CustomItem;
import com.sun.syndication.feed.rss.Item;
import com.sun.syndication.io.WireFeedParser;
import com.sun.syndication.io.impl.DateParser;
import com.sun.syndication.io.impl.RSS091UserlandParser;
import org.jdom.Element;
public class CustomParser extends RSS091UserlandParser implements WireFeedParser {
public CustomItem parseItem(Element rssRoot, Element eItem) {
CustomItem customItem = new CustomItem();
// Standard elements
Item standardItem = super.parseItem(rssRoot, eItem);
customItem.setTitle(standardItem.getTitle());
customItem.setDescription(standardItem.getDescription());
// Non-standard elements
Element e = eItem.getChild("customString", getRSSNamespace());
if (e != null) {
customItem.setCustomString(e.getText());
}
e = eItem.getChild("customDate", getRSSNamespace());
if (e != null) {
customItem.setCustomDate(DateParser.parseDate(e.getText()));
}
return customItem;
}
}
Finally you need to define your parser in a rome.properties file along with parsers for any other type of feed you want to handle.
# Feed Parser implementation classes
#
WireFeedParser.classes=com.example.CustomParser
You need to write a custom converter to get the data.
part of code same to above.
Start by extending the Item class to store the custom elements.
package com.example;
import com.sun.syndication.feed.rss.Item;
import java.util.Date;
public class CustomItem extends Item {
private String _customString;
private Date _customDate;
public String getCustomString() {
return _customString;
}
public void setCustomString(String customString) {
_customString = customString;
}
public Date getCustomDate() {
return _customDate;
}
public void setCustomDate(Date customDate) {
_customDate = customDate;
}
}
Then write the parser. You also need to handle any standard elements you want to parse.
package com.example;
import com.example.CustomItem;
import com.sun.syndication.feed.rss.Item;
import com.sun.syndication.io.WireFeedParser;
import com.sun.syndication.io.impl.DateParser;
import com.sun.syndication.io.impl.RSS091UserlandParser;
import org.jdom.Element;
public class CustomParser extends RSS091UserlandParser implements WireFeedParser {
public CustomItem parseItem(Element rssRoot, Element eItem) {
CustomItem customItem = new CustomItem();
// Standard elements
Item standardItem = super.parseItem(rssRoot, eItem);
customItem.setTitle(standardItem.getTitle());
customItem.setDescription(standardItem.getDescription());
// Non-standard elements
Element e = eItem.getChild("customString", getRSSNamespace());
if (e != null) {
customItem.setCustomString(e.getText());
}
e = eItem.getChild("customDate", getRSSNamespace());
if (e != null) {
customItem.setCustomDate(DateParser.parseDate(e.getText()));
}
return customItem;
}
}
Then write the converter.
public class CustomConverter extends ConverterForRSS20 {
protected SyndEntry createSyndEntry(Item item) {
List<HashMap<String,String>> temp = new ArrayList<HashMap<String,String>>();
SyndEntry syndEntry = super.createSyndEntry(item);
customItem customItem = (customItem)item;
List<String> customList = new ArrayList<String>();
customList.add( customItem.getCustomString() );
//set to empty attribute ex foreignmarkup
syndEntry.setForeignMarkup( customList );
return syndEntry;
}
}
Finally you need to define your parser in a rome.properties file along with parsers for any other type of feed you want to handle.
# Feed Parser implementation classes
#
WireFeedParser.classes=com.example.CustomParser
# Feed Converter implementation classes
#
Converter.classes=com.example.CustomConverter
Then you can get value.
SyndFeed feed = input.build(new XmlReader(feedUrl));
List<SyndEntryImpl> entrys = feed.getEntries();
for(SyndEntryImpl entry:entrys ){
System.out.println( entry.getForeignMarkup() );
}

Swiz 1.3.1 LogProcessor

i try everything to get the LogProcessor for Swiz to run.
Here are the project Foomonger.
I fear however, the ressources refer to an old version of swiz.
I want to implement the LogProceccor without the SwizLoggerConfig, because i need only the possibility to log some informations to thunderbolt. i need no further configuration. After that i start to write my own AbstractSwizLoggingTarget.
If i copy the class into my environment, i get the follow error:
TypeError: Error #1034: Typumwandlung fehlgeschlagen: org.swizframework.utils.logging::SwizLogger#e8aa8b1 kann nicht in mx.logging.ILogger umgewandelt werden.
(Sorry for the german text)
Der Quelltext:
package de.axurit.util
{
import org.swizframework.core.Bean;
import org.swizframework.processors.BaseMetadataProcessor;
import org.swizframework.processors.ProcessorPriority;
import org.swizframework.reflection.IMetadataTag;
import org.swizframework.utils.logging.SwizLogger;
public class LoggerProcessor extends BaseMetadataProcessor
{
protected static const LOGGER:String = "Logger";
public function LoggerProcessor()
{
super([LOGGER]);
}
override public function get priority():int
{
return ProcessorPriority.INJECT +1;
}
override public function setUpMetadataTag(metadataTag:IMetadataTag, bean:Bean):void
{
var logger:SwizLogger = SwizLogger.getLogger(bean.source);
bean.source[metadataTag.host.name] = logger; //here occurs the error
}
override public function tearDownMetadataTag(metadataTag:IMetadataTag, bean:Bean):void
{
bean.source[metadataTag.host.name] = null;
}
}
}
Can anyone help me how to create an own MetadataProcessor for central logging (not debuggin) in Swiz. I you need more code, let me know that
Thank you
Frank
It was a long, hard journey. Here is teh result:
package de.axurit.util
{
import org.swizframework.core.Bean;
import org.swizframework.processors.BaseMetadataProcessor;
import org.swizframework.reflection.IMetadataTag;
import org.swizframework.utils.logging.SwizLogger;
public class LoggerProcessor extends BaseMetadataProcessor
{
public function LoggerProcessor()
{
super(["Log"]);
}
override public function setUpMetadataTag(metadataTag:IMetadataTag, bean:Bean):void
{
super.setUpMetadataTag(metadataTag, bean);
bean.source [metadataTag.host.name] = SwizLogger.getLogger(bean.source);
}
override public function tearDownMetadataTag(metadataTag:IMetadataTag, bean:Bean):void
{
super.tearDownMetadataTag(metadataTag,bean);
bean.source[metadataTag.host.name] = null;
}
}
}

Help with this AS3 code

Hello im very new at AS3 so im a litle confused trying to get a simple modification to this code:
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.text.StyleSheet;
var fonts:Array /* of String */ = ["fonts/DroidSerif.swf","fonts/Lobster.swf"];
var fontsLoaded:int = 0;
var textStyleSheet:StyleSheet;
loadFonts();
function loadFonts():void
{
for each (var fontURL:String in fonts)
{
var fontLoader:Loader = new Loader();
fontLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onFontLoaded);
fontLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onFontLoadError);
fontLoader.load(new URLRequest(fontURL));
}
}
function onFontLoadError(event:IOErrorEvent):void
{
trace("ERROR: Could not find font "+event.target.loaderURL);
}
function onFontLoaded(event:Event):void
{
fontsLoaded++;
if (fontsLoaded == fonts.length) {
onFontsLoadComplete();
}}
function onFontsLoadComplete():void
{
trace("FONTS");
trace(fonts.length + " fonts have been loaded");
loadCSS();
}
function loadCSS():void
{
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onCSSLoadComplete);
loader.load(new URLRequest("css/styles.css"));
}
function onCSSLoadComplete(event:Event):void
{
trace("CSS");
textStyleSheet = new StyleSheet();
textStyleSheet.parseCSS(event.target.data);
loadXML();
}
function loadXML():void
{
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onXMLLoadComplete);
loader.load(new URLRequest("xml/content.xml"));
}
function onXMLLoadComplete(event:Event):void
{
// get xml from event target data
var xml:XML = XML(event.target.data);
// convert the xml to a string
var xmlString:String = xml;
// send xml string to the displayHTML method
trace("CARGO XML");
displayHTML(xmlString);
}
function displayHTML(htmlText:String):void
{
var htmlTextBlock:HTMLTextBlock = new HTMLTextBlock();
htmlTextBlock.blockWidth = 720;
htmlTextBlock.textStyleSheet = textStyleSheet;
htmlTextBlock.setHTML(htmlText);
htmlTextBlock.x = 0;
htmlTextBlock.y = 0;
addChild(htmlTextBlock);
trace("AJA");
}
Now, lets concentrate in the last function, displayHTML(). As you can see and i barely understand this function creates a textfield and fill it with the html content. I dont want to create a new textfield, i already have one dinamic textfield on the movie, with the html option selected. The problem is that there is something that im doing wrong, i use this simple line: mydinamictext.htmlText = htmlText. But the result is a NON css formated text. Here is a screen capture, the one of top is with the textfield created in code, and the bottom one with my textfield:
So, how can i apply the css and the fonts to my dynamic textfield and not create a new one. THANKS ALOT!
You would need to apply the CSS styles to the textfield on the stage. You were originally setting the CSS to the dynamically created text box within the displayHTML method.
As mentioned above, you will need to use the following:
mydinamictext.textStyleSheet = textStyleSheet;
You should be able to just use that line of code right above where you had mydinamictext.htmlText = htmlText
Best of luck.

embedding a Movieclip with flashDevelop

I am trying to embed a movieClip with flashDevelop but apparently its not working because its not recognizing the movieclips that are within it. here is my code
package com.objects{
import flash.display.MovieClip
import flash.text.TextField;
import flash.events.*;
import flash.text.TextFormat;
[Embed(source='../../../lib/fighter.swf', symbol='InfoBox')]
public class InfoBox extends gameObject {
protected var textf:TextField;
protected var s:String;
public var type:Boolean = false;
private var letter:Number = 0;
private var string:Array;
private var line:Number = 0;
private var portNum:Array;
public function InfoBox():void
{
portNum = new Array();
portrait.stop();
x = 400;
y = 550;
string = new Array();
var format = new TextFormat();
format.size = 18;
textf = new TextField();
textf.width = 550;
textf.height = 85;
textf.x = -220;
textf.y = -60;
textf.wordWrap = true;
textf.defaultTextFormat = format;
addChild(textf);
contButton.addEventListener(MouseEvent.MOUSE_DOWN, StoryNext);
}
private function StoryNext(e:MouseEvent):void
{
if(string.length > 1)
{
portNum.splice(0,1);
string.splice(0,1);
trace(string.length);
letter = 0;
}
else
{
contButton.removeEventListener(MouseEvent.MOUSE_DOWN, StoryNext);
dispatchEvent(new Event("StoryContinue"));
}
}
public function textInfo(msg:String,num:Number = 1):void
{
string.push(msg);
portNum.push(num);
}
override public function updateObject():void
{
TypeWords();
}// End UpdateObject
public function TypeWords():void
{
if(type)
{
portrait.gotoAndStop(portNum[0]);
var s:String = string[0];
if(letter <= s.length)
{
textf.text = s.substring(0,letter);
}
letter++
}
}
}
}
and I am getting this error
C:\Users\numerical25\Documents\RealGames\FighterPilot\beta1FlashDev\src\com\objects\InfoBox.as(23): col: 4 Error: Access of undefined property portrait.
portrait is a movie clip that I have inside of the info box movie clip. it is already on the stage and i gave it a instance name of portrait. It worked in flash, but now its not in flashDevelop
Try accessing the childs by name. It should work.
(getChildByName("portrait") as MovieClip).gotoAndStop(portNum[0]);
You need to define the corresponding properties on your class. In this case you can add:
public var portrait:MovieClip;
If it's some other type, for instance a Sprite you can change the definition to that.
EDIT: If you're having trouble setting up Flash Develop, I wrote some tutorials on that
[Embed(source='../../../lib/fighter.swf',
symbol='InfoBox')]
I'd say use SWCs not SWFs, it will make it a ****load easier.
SWCs keep all the stuff in place, whereas the swf can remove assets that are not used to save room.
Also in your flash develop panel you will see the swc (like the swf) and see all the classes that are included. Just right-click on it and add it to library. You won't have to use the [embed] code.
give that a try first, unless you absolutely need an swf.
To create an swc, use the flash tab under publish settings.
you can add linkage name for your MovieClip and export it as SWC, suppose named "mymc"
then copy SWC file to you FD project.
in your code, just addChild(new mymc());

Resources