OSMF serial composition with smooth streaming media element - actionscript-3

I want to create serial composition for smooth streaming media element with some specific portion of media element from multiple or single manifest(.isml). I have try to create serial composition with isml contain that clip section start from 10 sec to 50 sec and then add next element in serial composition for play 50 sec to 150 sec section from other manifest. but instead of play specified portion of manifest It play from start to end and once the first isml played it is not switch to next element of serial composition. when it check it's working on fire bug on mozila I found that fragment request is send continuously but player not able to show it.
code :-
package
{
import flash.display.*;
import com.microsoft.azure.media.AdaptiveStreamingPluginInfo;
import org.osmf.containers.MediaContainer;
import org.osmf.elements.SerialElement;
import org.osmf.elements.VideoElement;
import org.osmf.events.MediaErrorEvent;
import org.osmf.events.MediaFactoryEvent;
import org.osmf.events.MediaPlayerStateChangeEvent;
import org.osmf.layout.*;
import org.osmf.media.*;
import org.osmf.net.StreamType;
import org.osmf.net.StreamingURLResource;
import org.osmf.net.StreamingItemType;
[SWF(width="1024", height="768", backgroundColor='#ffffff')]
public class OSMFComposition extends Sprite
{
public var _container:MediaContainer;
public var _mediaFactory:DefaultMediaFactory;
private var _mediaPlayerSprite:MediaPlayerSprite;
private const Media_Url1:String="http://<media server>/Sintel/Sintel_H264.ism/manifest";
private const Media_Url2:String="http://<media server>/PushToPublishPoint/test.isml/manifest";
private const add1:String="assets/1.mp4"
private const add2:String="assets/2.mp4"
private var serialElement:SerialElement;
private var mediaPlayer:MediaPlayer;
private var container:MediaContainer;
public function OSMFComposition()
{
serialElement=new SerialElement();
mediaPlayer=new MediaPlayer();
stage.quality = StageQuality.HIGH;
initMediaPlayer();
}
private function initMediaPlayer():void
{
// Create a mediafactory instance
_mediaFactory = new DefaultMediaFactory();
// Add the listeners for PLUGIN_LOADING
_mediaFactory.addEventListener(MediaFactoryEvent.PLUGIN_LOAD,onPluginLoaded);
// Load the plugin class
loadAdaptiveStreamingPlugin( );
}
private function loadAdaptiveStreamingPlugin( ):void
{
var pluginResource:MediaResourceBase;
pluginResource = new PluginInfoResource(new AdaptiveStreamingPluginInfo( ));
_mediaFactory.loadPlugin( pluginResource );
}
private function onPluginLoaded( event:MediaFactoryEvent ):void
{
// The plugin is loaded successfully.
// Your web server needs to host a valid crossdomain.xml file to allow plugin to download Smooth Streaming files.
loadMediaSource();
}
private function loadMediaSource():void
{
var preRoll:MediaElement = _mediaFactory.createMediaElement( new URLResource(add1) );
var preRoll2:MediaElement = _mediaFactory.createMediaElement( new URLResource(add2) );
var resource1:StreamingURLResource=new StreamingURLResource(Media_Url1,null,10,50);
var element1:MediaElement = _mediaFactory.createMediaElement( resource1 );
var resource2:StreamingURLResource= new StreamingURLResource(Media_Url2,null,150,200);
var element2:MediaElement = _mediaFactory.createMediaElement( resource2 );
serialElement.addChild( preRoll);
serialElement.addChild(element2);
serialElement.addChild( preRoll2);
serialElement.addChild(element1);
mediaPlayer=new MediaPlayer(serialElement);
container=new MediaContainer();
container.addMediaElement(serialElement);
this.addChild(container);
}
}
}
Thanks

Related

save and load using sharedObject in AS3

i am currently doing an experiment to save each name of the user(not replacing it every time we save the new one).
my problem is the getLocal() function.I defined a variable with the type of string to make the SharedObject store the data to local storage with the name of the variable i defined which it is the name of the each user.
but i get this error:
Error #2134: Cannot create SharedObject. at
flash.net::SharedObject$/getLocal() at classes::Main/saveNewUser()
at classes::Main/promtSave()
here is my code
package classes {
import flash.display.MovieClip;
import flash.net.SharedObject;
import flash.text.TextField;
import classes.user.User;
public class Main extends MovieClip {
private var _user:User;
private var _properties:Object;
private var validOrNot_txt:TextField;
private var _name_input_txt:TextField;
//define a shared object to store our user data
private var database:SharedObject;
//define an array that will hold all users
private var userList:Array;
private var nameEntered:String;
public function Main() {
userList = [];
_name_input_txt = Name_input;
validOrNot_txt = valid_or_not_TXT;
validOrNot_txt.autoSize = 'center';
//_properties={Name:String,age:int,gender:String};
// constructor code
}
public function get user():User{
return _user;
}
private function saveNewUser():void{
nameEntered=_name_input_txt.text;
_user = new User();
_user._Name = _name_input_txt.text;
database = SharedObject.getLocal(nameEntered);
userList.push(_user);
database.data.Name = _user._Name;
}
}
}
here's the code in the timeline
import flash.events.MouseEvent;
login_btn.addEventListener(MouseEvent.CLICK, promtSave);
login_btn.buttonMode=true;
trace(Name_input.length);
function promtSave(e:MouseEvent):void{
if(Name_input.length>1){
saveNewUser();
}else{
throw(new Error('you did not enter anything'));
}
}
anybody, please help me with this :'(

Actionscript making intro of a game

I'm making a game in full classes. so the timeline is empty. But I want to use another scene for the game intro, after the intro, it will proceed to the main menu of the game which I have created. Anyone got an idea? I haven't found any since a week ago... I don't really know about how to operate scenes from code in classes. Please help. Thanks!
Here is the main code :
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.MovieClip;
public class Main extends Sprite
{
public var field:Array;
//CALL EVERY CLASS
public var _money:Money = new Money();
public var _gold:Gold;
public var _hero:Hero;
public var _enemy:Enemy;
private var _pause:MovieClip = new Pause();
private var pauseLayer:MovieClip = new PauseLayer();
private var ts:TitleScreen;
public function Main():void
{
ts = new TitleScreen();
addChild(ts);
}
//GAME FUNCTION
public function onStage():void
{
_hero = new Hero(this);
_enemy = new Enemy(this);
_gold = new Gold(this);
setupField();
_gold.goldSet(stage);
_money.addText(stage);
_hero.displayHero(stage);
_enemy.displayEnemy(stage);
setPause();
_pause.addEventListener(MouseEvent.CLICK, pauseGame);
}
private function setPause():void
{
addChild(_pause);
_pause.x = 620;
_pause.y = 50;
_pause.buttonMode = true;
}
private function pauseGame (e:MouseEvent):void
{
stage.frameRate = 0;
addChild(pauseLayer);
pauseLayer.alpha = 0.5;
pauseLayer.parent.setChildIndex(pauseLayer,numChildren-1);
}
//SET UP FIELD ARRAY
private function setupField():void
{
var fieldSprite:Sprite=new Sprite();
addChild(fieldSprite);
fieldSprite.graphics.lineStyle(4);
field=new Array();
for (var a:int=0; a<6; a++)
{
field[a]=new Array();
for (var b:int=0; b<10; b++)
{
field[a][b]=0;
}
}
//DRAW FIELD
for (var i:int=0; i<5; i++)
{
for (var j:int=0; j<9; j++)
{
fieldSprite.graphics.drawRect(75+65*j,50+75*i,65,75);
}
}
}
}
}
Titlescreen class :
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.Sprite;
public class TitleScreen extends Sprite
{
private var playBtn:MovieClip = new Resume();
public function TitleScreen()
{
playBtn.x = 50;
playBtn.y = 50;
playBtn.addEventListener(MouseEvent.CLICK, Play);
}
private function Play(e:MouseEvent):void
{
trace("a");
}
}
}
The most simple way would be using wrapper Sprites to hold each set of objects you probably want to be available as whole, say main menu, upgrades, storyline, etc etc. Then you just shift them in and out of display list to display corresponding "scene" with your Main class responsible of transition flow. But to do this you need to shift your game core functionality out of Main class into say Game class. That's how I have done the same thing in my game:
public class Main extends MovieClip {
private var so:SharedObject;
private var ui:UserInterface;
private var ts:TitleScreen;
private function init(e:Event = null):void
{
ui = new UserInterface();
ts = new TitleScreen();
ts.newButtonClicked = newGame;
ts.loadButtonClicked = loadGame;
ui.gotoMapBehavior = wentToMap;
addChild(ts);
}
Here, UserInterface is a class that has gaming logic inside, and TitleScreen is a main menu class. The functions are callbacks in Main:
private function newGame():void {
removeChild(ts); // hide title
if (!contains(ui)) addChild(ui);
SoundManager.playMusic(SoundManager.MUSIC_LEVELSELECT);
}
private function loadGame():void {
newGame();
ui.loadBattle(); // this should make UI load the battle from shared object (either supplied or received by itself)
}
private function wentToMap():void {
// we have just executed "go to map" from UI
removeChild(ui);
addChild(ts);
checkSO();
SoundManager.playMusic(SoundManager.MUSIC_INTRO);
}
The actual gaming logic does not interact with Main at all, except for shared object which is common for the entire project, but the link is received normally via SharedObject.getLocal(someName). The code is ugly, but could do for starters.
Save your game as SWF and make another project with timeline-animated intro. When the intro ends, make your project to load your game. Loader class can load other swf files. So, you don't need to edit your game classes.

Simple Camera in Actionscript/flex How to?

I am having no luck with trying to create a simple camera in actionscript. I don't want any controls- just a stage asking for permissions, then a livevideo of me in a window. Nothing fancy
Here's what I have so far: (the latest failure...)
package {
import flash.display.Sprite;
import flash.media.*;
public class FlashCamera extends Sprite
{
var cam:FlashCamera = Camera.getCamera();
var vid:Video = new Video();
vid.attachCamera(cam);
addChild(vid);
}
}
It's throwing this error when I try to compile this:
call to a possibly undefined method getCamera through a reference with static type Class
I'm compiling with flex in the windows command line like this:
(path to SDK)/bin/mxmlc Camera.as
Mind you, I am new to actionscript/flash development.
Can someone please explain what I am doing wrong?
For one thing, you're using classes of the name Camera from two different namespaces without disambiguating between the two. You'll probably also have to import other packages to support API versions of Camera and Video though (flash.media.Camera and flash.media.Video), but I'm not completely convinced this won't be done implicitly, especially not knowing the environment you're using.
Another thing you have to watch out for though, as far as realtime errors go, is when it takes the browser a few seconds to actually get the camera - just keep trying to grab it for at least a few seconds until it returns something other than null.
Found somethng that actually works, and will be adapting it for my needs:
package
{
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Camera;
import flash.media.Microphone;
import flash.media.Video;
public class FlashVideo extends Sprite
{
private var nc:NetConnection;
private var good:Boolean;
private var rtmpNow:String;
private var nsIn:NetStream;
private var nsOut:NetStream;
private var cam:Camera;
private var mic:Microphone;
private var vidLocal:Video;
private var vidStream:Video;
public function FlashVideo()
{
trace("Hello testing");
rtmpNow = "rtmp://localhost/LiveStreams";
nc=new NetConnection();
nc.connect(rtmpNow);
nc.addEventListener(NetStatusEvent.NET_STATUS,checkCon);
setCam();
setMic();
setVideo();
}
private function checkCon(e:NetStatusEvent):void
{
good = e.info.code == "NetConnection.Connect.Success";
if (good)
{
nsOut = new NetStream(nc);
nsOut.attachAudio(mic);
nsOut.attachCamera(cam);
nsOut.publish("left","live");
nsIn = new NetStream(nc);
nsIn.play("right");
vidStream.attachNetStream(nsIn);
}
}
private function setCam()
{
cam = Camera.getCamera();
cam.setKeyFrameInterval(9);
cam.setMode(640,400,30);
cam.setQuality(0,95);
}
private function setMic()
{
mic = Microphone.getMicrophone();
mic.gain = 85;
mic.rate = 11;
mic.setSilenceLevel(15,2000);
}
private function setVideo()
{
vidLocal = new Video(cam.width,cam.height);
addChild(vidLocal);
vidLocal.x = 15;
vidLocal.y = 30;
vidLocal.attachCamera(cam);
vidStream = new Video(cam.width,cam.height);
addChild(vidStream);
vidStream.x=(vidLocal.x+ cam.width +10);
vidStream.y = vidLocal.y;
}
}
}

flash as3 serial port

Hey trying to bring data in through the serial port but i get this error.
1037: Packages cannot be nested.
I then need to take these values and use 1 to control video playback and the other to control the audio volume
package
{
import flash.display.Sprite;
import flash.net.XMLSocket;
import flash.events.DataEvent;
public class receiveData extends Sprite
{
public static const PORT:Number = 5331;
public static const COMMA:String = ",";
public static const LOCALHOST:String = "127.0.0.1";
private var socket:XMLSocket = null;
public function receiveData()
{
super();
init();
}
private function init():void
{
socket = new XMLSocket();
socket.addEventListener( DataEvent.DATA, doSocketData );
socket.connect( LOCALHOST, PORT );
}
protected function doSocketData( event:DataEvent ):void
{
var parts:Array = null;
var sensorone:Number = 0;
var sensortwo:Number = 0;
var values:String = event.data.toString();
parts = values.split( COMMA );
trace( parts[0]);
trace( parts[1]);
sensorone = new Number( parts[0] );
sensortwo = new Number( parts[1] );
}
}
}
So basically you need to put that code in a separate AS3 file and set that as the document class or as the class file for a MovieClip you make in Flash. Alternatively you could use a different IDE like FlashBuilder or FlashDevelop or FDT and avoid the Flash IDE (which as a programmer primarily I feel muddles things up quite a bit).
http://www.actionscript.org/forums/showthread.php3?t=136364 (haha SO won't let me LMGTFY)
Looks like you're on the right track though if you're using tinkerproxy or something of the sort to forward the data (have fun I gotta get myself back into that, check out links in th description of my vid http://www.youtube.com/watch?v=71eFWknHKEM&list=UUSz-eugjE1d6yki6ZT51CKg&index=17&feature=plcp :)

AS3 public variable won't store values

first time poster here.
So I'm building a "multi-RSS feed reader" and I've broken this into 2 classes, a "TechFeed.as" and a "Feed.as"; The tech feed instantiates multiple feeds by passing URL's to a new Feed object.
My issue at the moment is that in the Feed.as I have a couple public variables which are used in TechFeed.as to display basic details about the feed, however, these variables refuse to retain any value I give them within Feed.as's functions, and are turning up "null".
Edit: Also maybe something to note; TechFeed.as is the main AS file the stage uses.
TechFeed.as
package {
import flash.display.MovieClip;
public class TechFeed extends MovieClip {
private var feed_one:Feed = new Feed("http://feeds.feedburner.com/crunchgear");
private var feed_two:Feed = new Feed("http://feeds.mashable.com/Mashable");
private var feed_three:Feed = new Feed("http://www.engadget.com/rss.xml");
public function TechFeed() {
trace(feed_one.feed_title);
//feed_name.text = feed_one.getFeedTitle();
}
}
}
Feed.as
package {
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
public class Feed {
//Public variables to display feed info
public var feed_title:XMLList;
public var feed_desc:String;
public var feed_link:String;
//Setting up variables which help load the feeds
private var feedXML:XML;
//Create a loader to load an external URL
private var loader:URLLoader = new URLLoader();
public function Feed(inURL:String = "") {
//Load the xml document
loader.load(new URLRequest(inURL));
loader.addEventListener(Event.COMPLETE,onLoaded);
}
//When the loader had loaded the xml document, pass that into a variable for use.
private function onLoaded(e:Event):void {
feedXML = new XML(e.target.data);
// break down the xml document elements into singular XML array lists
//Feed details
this.feed_title = feedXML.channel.title;
this.feed_link = feedXML.channel.link;
this.feed_desc = feedXML.channel.description;
trace(this.feed_title);
}
}
}
Any help will be greatly appreciated :)
Thanks,
Geoff
Your problem is timing you are trying to write the data from the feed before it is returned from the server.
In this example I assign a function to call back on when the data is loaded.
package {
import flash.display.MovieClip;
public class TechFeed extends MovieClip {
private var feed_one:Feed;
private var feed_two:Feed;
private var feed_three:Feed;
public function TechFeed() {
feed_one= new Feed("http://feeds.feedburner.com/crunchgear",assignResults);
feed_two= new Feed("http://feeds.mashable.com/Mashable",assignResults);
feed_three= new Feed("http://www.engadget.com/rss.xml",assignResults);
}
public function assignResults(value:value):void{
feed_name.text = value;
}
}
}
package {
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
public class Feed {
//Public variables to display feed info
public var feed_title:XMLList;
public var feed_desc:String;
public var feed_link:String;
//Setting up variables which help load the feeds
private var feedXML:XML;
//Create a loader to load an external URL
private var loader:URLLoader = new URLLoader();
private var _callBackFunc:Function;
public function Feed(inURL:String = "", callBackFunc:Function) {
this._callBackFunc = callBackFunc;
//Load the xml document
loader.load(new URLRequest(inURL));
loader.addEventListener(Event.COMPLETE,onLoaded);
}
//When the loader had loaded the xml document, pass that into a variable for use.
private function onLoaded(e:Event):void {
feedXML = new XML(e.target.data);
// break down the xml document elements into singular XML array lists
//Feed details
this.feed_title = feedXML.channel.title;
this.feed_link = feedXML.channel.link;
this.feed_desc = feedXML.channel.description;
this._callBackFunc(this.feed_title);
}
}
}
If the problem is that feed_one.feed_title is coming up null in the TechFeed() ctor, that is because you are not waiting for the feed to finish loading.
What you aught to do is dispatch an event from the Feed when it is done loading and processing the data, catch it in TechFeed and then use the public variables as you please (this also means that your Feed class will have to subclass EventDispatcher):
In Feed class:
private function onLoaded(e:Event):void {
feedXML = new XML(e.target.data);
// break down the xml document elements into singular XML array lists
//Feed details
this.feed_title = feedXML.channel.title;
this.feed_link = feedXML.channel.link;
this.feed_desc = feedXML.channel.description;
trace(this.feed_title);
dispatchEvent(new Event(Event.COMPLETE));////Dispatch Event
}
In TechFeed class:
public function TechFeed() {
trace(feed_one.feed_title);//This will trace "null"
feed_one.addEventListener(Event.COMPLETE, dataLoaded);//add event listener
}
private function dataLoaded(e:Event):void{
var feed = Feed(e.currentTarget);
feed.removeEventListener(Event.COMPLETE, dataLoaded);//remove event listener to prevent memory leaks
trace(feed.feed_title);// This will trace the correct title
}