2009년 9월 8일 화요일

FLV를 자바스크립트로 제어

// 비디오 준비

var connection_nc:NetConnection = new NetConnection();
var videoDuration:Number;
connection_nc.connect(null);

 

var stream_ns:NetStream = new NetStream(connection_nc);
stream_ns.setBufferTime(5);

 

// 사운드 준비

this.createEmptyMovieClip("sound_mc",this.getNextHighestDepth());
sound_mc.attachAudio(stream_ns);
var audio_sound:Sound = new Sound(sound_mc);
var currentVolume:Number = 50;

audio_sound.setVolume(currentVolume);

 

// 비디오 재생

function playVideo() {
 my_video.attachVideo(stream_ns);
 targetStream.play("비디오주소");

 

stream_ns.onMetaData = function(obj) {
  trace("비디오 크기  "+obj.duration);
 };

// 참고

// 현재 재생중인 위치값 알고싶을땐

// stream_ns.time

}

 

// 비디오 일시정지

function pauseVideo() {
 stream_ns.pause(true);
}

 

// 비디오 정지 후 다시 재생

function playVideo_afterPause() {
stream_ns.pause(false);
}

 

// 비디오 정지

function stopVideo() {
stream_ns.seek(0); // seek : 이 값을 정해주면 원하는 위치로 비디오 재생이 가능하다.
stream_ns.pause(true);
}