I'm not sure why i'm getting the following error. Can you please suggest what change in my code needed to successfully play the rtmp stream on my stage?
error:
NetConnection.Connect.Success Error #2044: Unhandled NetStatusEvent:.
level=error, code=NetStream.Play.StreamNotFound at
main/attachnetstream()[/Users/user/Desktop/ojotha/main.as:24] Debug
session terminated.
package {
import flash.display.MovieClip;
import flash.net.*;
import flash.events.NetStatusEvent;
import flash.media.Video;
public class main extends MovieClip {
public var streamserver:String="rtmp://216.245.200.114/live";
public var streamname:String="shomoy";
public var netconnection:NetConnection=new NetConnection();
public function main() {
netconnection.connect(streamserver);
netconnection.addEventListener(NetStatusEvent.NET_STATUS, attachnetstream);
}
public function attachnetstream(event:NetStatusEvent):void{
trace(event.info.code);
switch (event.info.code) {
case "NetConnection.Connect.Success":
var netstream:NetStream=new NetStream(netconnection);
var video:Video=new Video();
video.attachNetStream(netstream);
netstream.play(streamname);
video.height=480;
video.width=640;
addChild(video);
break;
case "NetStream.Play.StreamNotFound":
trace("stream not found");
break;
}
}
}
}
You should add NetStatusEvent event listener to your stream as well.
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
Look at the docs
You may also need to set another event listener, even if it is empty to prevent some other runtime errors.
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
Related
if i am using the mediaplayback component in Adobe flash, the videostream on a crtmp-server runs correctly.
if i try to do this on my own without using that component i got some errors, unluckily there is no much support explaining streaming over as3 without a mediaplayback-component.
i have following code
package
{
import flash.display.MovieClip;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
/**
* ...
* #author Siam Modi
*/
public class Main extends MovieClip
{
public function Main()
{
var nc:NetConnection = new NetConnection();
nc.connect("rtmp://213.136.73.230/maya");
var vid:Video = new Video();
addChild(vid);
var ns:NetStream = new NetStream(nc);
vid.attachNetStream(ns);
ns.play("atlas.mp4");
}
}
}
Any ideas ? Thx for help
You can connect a NetStream to a NetConnection instance only after it fires a NetStatusEvent with NetConnection.Connect.Succes info.code.
To get this event you need to call nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler)
before calling
nc.connect("rtmp://213.136.73.230/maya");
and there attach NetStream / Video:
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
var ns:NetStream = new NetStream(nc);
vid.attachNetStream(ns);
ns.play("atlas.mp4");
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + videoURL);
break;
}
}
here is an example from the reference
I'm publishing a Flash game I'm making in AIR 2.6 rather than Flash Player, since that's the only way I can get it to work with TCP. For some reason though, doing this will not allow me to import packages, seemingly...
If I have it published through Flash Player, this code works fine:
import TCP;
addEventListener(Event.ENTER_FRAME, TCP);
When I do the same exact thing but publish with AIR 2.6, I get this error:
1067: Implicit coercion of a value of type Class to an unrelated type Function.
This is the entire package:
package
{
import flash.display.Sprite;
import flash.events.EventDispatcher;
import flash.events.Event;
import flash.events.*;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.ServerSocketConnectEvent;
import flash.net.ServerSocket;
import flash.net.Socket;
public class TCP extends Sprite
{
private var serverSocket:ServerSocket;
private var clientSockets:Array = new Array();
public function TCP()
{
try
{
// Create the server socket
serverSocket = new ServerSocket();
// Add the event listener
serverSocket.addEventListener( Event.CONNECT, connectHandler );
serverSocket.addEventListener( Event.CLOSE, onClose );
// Bind to local port 8087
serverSocket.bind( 8087, "127.0.0.1" );
// Listen for connections
serverSocket.listen();
trace( "Listening on " + serverSocket.localPort );
}
catch(e:SecurityError)
{
trace(e);
}
}
public function connectHandler(event:ServerSocketConnectEvent):void
{
//Thesocket is provided by the event object
var socket:Socket = event.socket as Socket;
clientSockets.push( socket );
socket.addEventListener( ProgressEvent.SOCKET_DATA, socketDataHandler);
socket.addEventListener( Event.CLOSE, onClientClose );
socket.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
//Send a connect message
socket.writeUTFBytes("Connected.");
socket.flush();
trace( "Sending connect message" );
}
public function socketDataHandler(event:ProgressEvent):void
{
var socket:Socket = event.target as Socket
//Read the message from the socket
var message:String = socket.readUTFBytes( socket.bytesAvailable );
trace( "Received: " + message);
// Echo the received message back to the sender
message = "Echo -- " + message;
socket.writeUTFBytes( message );
socket.flush();
trace( "Sending: " + message );
}
private function onClientClose( event:Event ):void
{
trace( "Connection to client closed." );
//Should also remove from clientSockets array...
}
private function onIOError( errorEvent:IOErrorEvent ):void
{
trace( "IOError: " + errorEvent.text );
}
private function onClose( event:Event ):void
{
trace( "Server socket closed by OS." );
}
}}
So what do I have to do here? I believe the package is "importing", but when I use addEventListener I get that error thrown at me. Again, this only happens when I publish with AIR. What do I do?
There should be no reason to add an enterframe listener. It looks like the TCP class should function is is...
var tcp:TCP = new TCP();
Should instantiate the class. Its constructor will then try to make a socket connection.
Error is correct, you should add event listener like:
addEventListener(Event.ENTER_FRAME, onEnterFrameFunction);
Then in onEnterFrameFunction, you can use the TCP class:
var tcp:TCP = new TCP();
I am surprised that works in flash. Maybe you are not describing things fully.
In the code below you are trying to add an eventlistener with a Class as the function to be called when the event occurs.
import TCP;
addEventListener(Event.ENTER_FRAME, TCP);
So the error is correct:
1067: Implicit coercion of a value of type Class to an unrelated type Function.
It is not clear from your question what you are trying to do with the event listener.
Is it possible to use a URLLoader in a class?
I am trying to use it in a class. Code is taken from: http://www.republicofcode.com/tutorials/flash/as3externaltext/
And here is my class I am trying to use it in but I get this error:
C:\Users\com\defaultVars.as, Line 36 1046: Type was not found or was not a compile-time constant: Event.**
package com {
import flash.display.Stage;
import flash.*;
public class defaultVars
{
// loader
public var myTextLoader:URLLoader = new URLLoader();
public function defaultVars()
{
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
myTextLoader.load(new URLRequest("myText.txt"));
}
public function sampleFunction()
{
// trace("not used");
}
/// ERROR LINE right below. But even if I fix this I get more errors.
function onLoaded(e:Event):void {
trace(e.target.data);
}
////////////////////////
}
}
try adding this to the top of your file.
import flash.events.*
import flash.net.*;
I'm building an application with an Strobe Media Playback in it and I can't play a RTMP stream.
The weird thing here is that I can play the stream on JWPlayer and even in a simple Flash video player with the classic NetStream and NetConnection code.
http://www.longtailvideo.com/jw-player/wizard/
This is the stream: rtmp://fl.world-television.com/streamstudio/vod/flv:endesa/20130422/video_full_es_v2.flv
I don't know if I need to set up any special configuration through the OSMF params.
This is how I have been played the video in a simple Flash CS application.
package {
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.Event;
public class VideoTest extends Sprite {
private var videoURL:String = "rtmp://fl.world-television.com/streamstudio/vod/flv:endesa/20130422/video_full_es_v2.flv";
private var connection:NetConnection;
private var stream:NetStream;
public function VideoTest()
{
initialize();
}
private function initialize():void
{
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect("rtmp://fl.world-television.com/streamstudio/vod/" );
}
private function netStatusHandler(event:NetStatusEvent):void {
trace("net status handler: " + event.info.code);
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + videoURL);
break;
}
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function connectStream():void
{
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
var video:Video = new Video();
video.attachNetStream(stream);
stream.play("endesa/20130422/video_full_es_v2");
addChild(video);
}
}
}
I really think that the problem here is that OSMF it's not slicing the URL correctly and it's trying to connect (NetConnection) or trying to play (NetStream) a bad String.
EDIT:
Solved removing "/vod" in the URL.
You could try it here:
http://osmf.org/dev/2.0gm/debug.html?wmode=direct&width=470&height=320&src=rtmp%3A%2F%2Ffl.world-television.com%2Fstreamstudio%2Fendesa%2F20130422%2Fvideo_full_es_v2
I am getting a null object error when I add the mouse event listener for the log in button. (Look at the comments in the constructor)
I am using Flash CS6, and objects such as logInbutton and screen_log_in are instance names from the .fla file. This here is the .as file.
Error I get is:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at actions::indexPage()
My AS3 code:
package actions
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.IEventDispatcher;
import flash.net.URLRequest;
import flash.display.Loader;
import fl.motion.MotionEvent;
import flash.events.MouseEvent;
public class indexPage extends MovieClip
{
public function indexPage():void
{
loadSWF("http://mathlympics.cu.cc/loginsystem.swf");
//THIS IS THE LINE WHICH IS CAUSING THE ERROR
//WHEN I COMMENT IT OUT THE ERROR IS GONE
logInButton.addEventListener(MouseEvent.CLICK, goToLogIn);
}
var _swfLoader:Loader;
var _swfContent:MovieClip;
public function loadSWF(path:String):void
{
var _req:URLRequest = new URLRequest();
_req.url = path;
_swfLoader = new Loader();
setupListeners(_swfLoader.contentLoaderInfo);
_swfLoader.load(_req);
}
function setupListeners(dispatcher:IEventDispatcher):void
{
dispatcher.addEventListener(Event.COMPLETE, addSWF);
}
function addSWF(event:Event):void
{
event.target.removeEventListener(Event.COMPLETE, addSWF);
event.target.removeEventListener(ProgressEvent.PROGRESS, preloadSWF);
_swfContent = event.target.content;
screen_log_in.addChild(_swfContent);
}
function unloadSwf():void
{
_swfLoader.unloadAndStop();
screen_log_in.removeChild(_swfContent);
_swfContent = null;
}
function goToLogIn(e:MouseEvent):void
{
unloadSwf();
screen_log_in.loadSWF("http://mathlympics.cu.cc/loginsystem.swf");
}
function goToRegister(e:MouseEvent):void
{
unloadSwf();
screen_log_in.loadSWF("http://mathlympics.cu.cc/register.swf");
}
}
}
You can not access stage until stage is available.
public function indexPage():void
{
addEventListener(Event.ADDED_TO_STAGE,init)
}
public function init(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE,init)
loadSWF("http://mathlympics.cu.cc/loginsystem.swf");
//THIS IS THE LINE WHICH IS CAUSING THE ERROR
//WHEN I COMMENT IT OUT THE ERROR IS GONE
logInButton.addEventListener(MouseEvent.CLICK, goToLogIn);
}
I am just going to answer my question for the future visitors. The cause of problem I have note been able to figure out but what I have figured out is how to get around it. I simply copy pasted my code from document class to the frames and it works absolutely fine there.