| 1 | |
|---|
| 2 | package { |
|---|
| 3 | |
|---|
| 4 | import flash.display.Sprite; |
|---|
| 5 | import flash.net.NetConnection; |
|---|
| 6 | import flash.events.NetStatusEvent; |
|---|
| 7 | import flash.events.SecurityErrorEvent; |
|---|
| 8 | import flash.events.AsyncErrorEvent; |
|---|
| 9 | import flash.media.Video; |
|---|
| 10 | import flash.net.NetStream; |
|---|
| 11 | import flash.net.ObjectEncoding; |
|---|
| 12 | import flash.text.TextField; |
|---|
| 13 | |
|---|
| 14 | public class Player extends Sprite |
|---|
| 15 | { |
|---|
| 16 | private var _connection : NetConnection; |
|---|
| 17 | private var _stream : NetStream; |
|---|
| 18 | private var _video : Video; |
|---|
| 19 | private var _textY : Number; |
|---|
| 20 | |
|---|
| 21 | public function Player() |
|---|
| 22 | { |
|---|
| 23 | _connection = new NetConnection(); |
|---|
| 24 | _connection.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); |
|---|
| 25 | _connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError); |
|---|
| 26 | _connection.objectEncoding = ObjectEncoding.AMF0; |
|---|
| 27 | _connection.connect("rtmp://127.0.0.1:2935/fastplay/"); |
|---|
| 28 | _textY = 0; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | private function onNetStatus( event : NetStatusEvent ) : void |
|---|
| 32 | { |
|---|
| 33 | var output:TextField = new TextField(); |
|---|
| 34 | output.width = 10000; |
|---|
| 35 | output.text = event.info.code; |
|---|
| 36 | output.antiAliasType = flash.text.AntiAliasType.ADVANCED |
|---|
| 37 | output.x = 0; |
|---|
| 38 | output.y = _textY; |
|---|
| 39 | output.scaleX = output.scaleY = 0.5; |
|---|
| 40 | addChild(output); |
|---|
| 41 | _textY += 10; |
|---|
| 42 | |
|---|
| 43 | switch(event.info.code){ |
|---|
| 44 | case "NetConnection.Connect.Success": |
|---|
| 45 | _stream = new NetStream(_connection); |
|---|
| 46 | _stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); |
|---|
| 47 | _stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError); |
|---|
| 48 | |
|---|
| 49 | var video : Video = new Video(320, 180); |
|---|
| 50 | video.attachNetStream(_stream); |
|---|
| 51 | video.deblocking = 2; |
|---|
| 52 | video.smoothing = true; |
|---|
| 53 | |
|---|
| 54 | _stream.play("test.mp4"); |
|---|
| 55 | addChild(video); |
|---|
| 56 | _video = video |
|---|
| 57 | break; |
|---|
| 58 | |
|---|
| 59 | case "NetStream.Play.StreamNotFound": |
|---|
| 60 | trace("File not found"); |
|---|
| 61 | break; |
|---|
| 62 | default: |
|---|
| 63 | break; |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | private function onSecurityError( event : SecurityErrorEvent ) : void |
|---|
| 68 | { |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | private function onAsyncError( event : AsyncErrorEvent ) : void |
|---|
| 72 | { |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | } |
|---|