两个视频流AS3错误



我有2个NetStream对象,我试图分配2个视频(每个一个),然后,因为我有2个本机窗口,我使用stage.addChild(video);secondWindow.stage.addChild(video2);。我使用stream.play("scene1.f4v");stream2.play("scene1A.f4v");来指定流的文件。我现在正在诊断一个错误,因为视频没有播放。相反,我得到以下错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference。at Function/detectText()[/Users/Jared/Documents/Adobe Flash Builder 4.7/InTheAirNet_MultiviewPlayer/src/InTheAirNet_MultiviewPlayer.as:124]

第124行是secondWindow.stage.addChild(video2);。这个错误是由于我的文件url的问题?我有一个名为assets的文件夹中的视频文件在我的应用程序的结构。

我认为这就足够了,但我也会包括我的代码-以防万一:

package
{
import flash.desktop.NativeApplication;
import flash.display.NativeWindow;
import flash.display.NativeWindowInitOptions;
import flash.display.NativeWindowSystemChrome;
import flash.display.Screen;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.events.KeyboardEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;

public class InTheAirNet_MultiviewPlayer extends Sprite {
    public var secondWindow:NativeWindow;
    public static var nativeApplication:Object;
    private var connection:NetConnection;
    private var stream:NetStream;
    private var stream2:NetStream;
    private var video:Video;
    private var video2:Video;
    public function InTheAirNet_MultiviewPlayer() {
        // Ouput screen sizes and positions (for debugging)
        for each (var s:Screen in Screen.screens) trace(s.bounds);                
        // Make primary (default) window's stage go fullscreen
        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
        stage.color = 0xC02A2A; // red

        // Create fullscreen window on second monitor (check if available first)
        if (Screen.screens[1]) {
            // Second window
            var nwio:NativeWindowInitOptions = new NativeWindowInitOptions();
            nwio.systemChrome = NativeWindowSystemChrome.NONE;
            secondWindow = new NativeWindow(nwio);
            secondWindow.bounds = (Screen.screens[1] as Screen).bounds;
            secondWindow.activate();
            // Second window's stage
            secondWindow.stage.align = StageAlign.TOP_LEFT;
            secondWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
            secondWindow.stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
            secondWindow.stage.color = 0x387D19; // green   
        }
        //Create array of scenes and their overlays
        var videos:Array = [
            {
                primary:'scene1.f4v',
                secondary:['scene1A.f4v','scene1B.f4v']
            },
            {
                primary:'scene2.f4v',
                secondary:['scene2A.f4v','scene2B.f4v']
            },
            {
                primary:'scene3.f4v',
                secondary:['scene3A.f4v','scene3B.f4v']
            },
            {
                primary:'scene4.f4v',
                secondary:['scene4A.f4v','scene4B.f4v']
            },
            {
                primary:'scene5.f4v',
                secondary:['scene5A.f4v','scene5B.f4v']
            }
        ]
        //Keyboard event listener and key assignment
        stage.addEventListener(KeyboardEvent.KEY_DOWN, detectText);
        function detectText(keyboardevent:KeyboardEvent):void {
            if (keyboardevent.keyCode == 38) { //UP
                //Previous scene
            }
            if (keyboardevent.keyCode == 40) { //DOWN
                //Next scene
            }
            if (keyboardevent.keyCode == 37) { //LEFT
                //Previous overlay
            }
            if (keyboardevent.keyCode == 39) { //RIGHT
                //Next overlay
            }
            if (keyboardevent.keyCode == 27) { //ESCAPE
                //Terminate application
                NativeApplication.nativeApplication.exit(); 
            }
            //START static video objects for BETA
            //Create the NetConnection
            connection = new NetConnection();
            //Set NetConnection to streaming mode; null specifies NO media server connection
            connection.connect(null);
            //Create the NetStream
            stream = new NetStream(connection);
            stream2 = new NetStream (connection);
            //Set NetStream client to recieve certain events
            stream.client = this;
            stream2.client = this;
            //Create video objects
            var video:Video = new Video();
            var video2:Video = new Video();
            //Add video objects to their stages
            stage.addChild(video);
            secondWindow.stage.addChild(video2);
            //Attach the NetStream to the video object
            video.attachNetStream(stream);
            video2.attachNetStream(stream2);
            //Set the default buffer time to 1 second
            stream.bufferTime = 1;
            stream2.bufferTime = 1;
            //Tell the stream to recieve the video
            stream.receiveVideo(true);
            stream2.receiveVideo(true);
            //Play a F4V file
            stream.play("scene1.f4v");
            stream2.play("scene1A.f4v");
        }
    }
        }
}

我已经知道哪里不对了。我让应用程序在检测到存在第二个监视器时创建第二个本机窗口。然而,在我创建NetConnection、流和视频头的代码中,我根本没有使用IF语句。因此,当我试图在没有第二个监视器的情况下运行应用程序时,没有第二个本机窗口来运行视频-因此出现了错误。

现在我要弄清楚为什么第一个本机窗口的视频没有播放

相关内容

  • 没有找到相关文章

最新更新