我有2个NetStream对象,我试图分配2个视频(每个一个),然后,因为我有2个本机窗口,我使用stage.addChild(video);
和secondWindow.stage.addChild(video2);
。我正在使用stream.play("scene1.f4v");
和stream2.play("scene1A.f4v");
来指定流的文件。我现在正在诊断错误,因为视频没有播放。相反,我收到以下错误:
TypeError:错误#1009:无法访问空对象引用的属性或方法。 at Function / detectText()[/ Users / Jared / Documents / Adobe Flash Builder 4.7 / InTheAirNet_MultiviewPlayer / src / InTheAirNet_MultiviewPlayer.as:124]
第124行是secondWindow.stage.addChild(video2);
。这个错误是由于我的文件URLS问题吗?我将视频文件放在我的应用程序结构中名为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");
}
}
}
}
答案 0 :(得分:0)
我发现了什么是错的。我有应用程序创建第二个本机窗口,如果它检测到第二个监视器的存在。但是,在我创建NetConnection,流和视频头的代码中,我根本不使用IF语句。因此,当我尝试在没有第二个监视器的情况下运行应用程序时,没有辅助本机窗口来运行视频头 - 因此出错。
现在我将不得不弄清楚为什么第一个原生窗口的视频没有播放。