| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| NativeNetStreamAdapter |
|
| 0.0;0 |
| 1 | /* | |
| 2 | * Licensed under the MIT License | |
| 3 | * | |
| 4 | * Copyright 2011 (c) Flávio Silva, flsilva.com | |
| 5 | * | |
| 6 | * Permission is hereby granted, free of charge, to any person | |
| 7 | * obtaining a copy of this software and associated documentation | |
| 8 | * files (the "Software"), to deal in the Software without | |
| 9 | * restriction, including without limitation the rights to use, | |
| 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| 11 | * copies of the Software, and to permit persons to whom the | |
| 12 | * Software is furnished to do so, subject to the following | |
| 13 | * conditions: | |
| 14 | * | |
| 15 | * The above copyright notice and this permission notice shall be | |
| 16 | * included in all copies or substantial portions of the Software. | |
| 17 | * | |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
| 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | |
| 20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
| 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
| 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
| 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
| 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
| 25 | * OTHER DEALINGS IN THE SOFTWARE. | |
| 26 | * | |
| 27 | * http://www.opensource.org/licenses/mit-license.php | |
| 28 | */ | |
| 29 | 0 | package org.vostokframework.domain.loading.states.fileloader.adapters |
| 30 | { | |
| 31 | import org.vostokframework.domain.loading.states.fileloader.algorithms.events.FileLoadingAlgorithmMediaEvent; | |
| 32 | ||
| 33 | import flash.events.IEventDispatcher; | |
| 34 | import flash.net.NetConnection; | |
| 35 | import flash.net.NetStream; | |
| 36 | import flash.net.URLRequest; | |
| 37 | ||
| 38 | /** | |
| 39 | * description | |
| 40 | * | |
| 41 | * @author Flávio Silva | |
| 42 | */ | |
| 43 | public class NativeNetStreamAdapter extends DataLoaderAdapter | |
| 44 | { | |
| 45 | /** | |
| 46 | * @private | |
| 47 | */ | |
| 48 | private var _clientCallback:Object; | |
| 49 | private var _netStream:NetStream; | |
| 50 | private var _netConnection:NetConnection; | |
| 51 | private var _request:URLRequest; | |
| 52 | ||
| 53 | /** | |
| 54 | * description | |
| 55 | * | |
| 56 | * @param loader | |
| 57 | * @param request | |
| 58 | * @param context | |
| 59 | */ | |
| 60 | public function NativeNetStreamAdapter(netStream:NetStream, netConnection:NetConnection, request:URLRequest) | |
| 61 | 0 | { |
| 62 | 0 | if (!netStream) throw new ArgumentError("Argument <netStream> must not be null."); |
| 63 | 0 | if (!netConnection) throw new ArgumentError("Argument <netConnection> must not be null."); |
| 64 | 0 | if (!request) throw new ArgumentError("Argument <request> must not be null."); |
| 65 | ||
| 66 | 0 | _netStream = netStream; |
| 67 | 0 | _netConnection = netConnection; |
| 68 | 0 | _request = request; |
| 69 | ||
| 70 | 0 | _clientCallback = { }; |
| 71 | 0 | _clientCallback["onMetaData"] = metaDataHandler; |
| 72 | 0 | _clientCallback["onCuePoint"] = cuePointHandler; |
| 73 | ||
| 74 | 0 | _netStream.client = _clientCallback; |
| 75 | 0 | } |
| 76 | ||
| 77 | override protected function doCancel(): void | |
| 78 | { | |
| 79 | 0 | close(); |
| 80 | 0 | } |
| 81 | ||
| 82 | override protected function doDispose():void | |
| 83 | { | |
| 84 | 0 | close(); |
| 85 | ||
| 86 | 0 | _netStream = null; |
| 87 | 0 | _request = null; |
| 88 | 0 | } |
| 89 | ||
| 90 | override protected function doGetData():* | |
| 91 | { | |
| 92 | 0 | return _netStream; |
| 93 | } | |
| 94 | ||
| 95 | /** | |
| 96 | * description | |
| 97 | */ | |
| 98 | override protected function doLoad(): void | |
| 99 | { | |
| 100 | 0 | _netStream.play(_request.url); |
| 101 | 0 | } |
| 102 | ||
| 103 | /** | |
| 104 | * description | |
| 105 | */ | |
| 106 | override protected function doStop():void | |
| 107 | { | |
| 108 | 0 | close(); |
| 109 | 0 | } |
| 110 | ||
| 111 | override protected function getLoadingDispatcher():IEventDispatcher | |
| 112 | { | |
| 113 | 0 | return _netStream; |
| 114 | } | |
| 115 | ||
| 116 | private function close():void | |
| 117 | { | |
| 118 | try | |
| 119 | { | |
| 120 | 0 | _netStream.pause(); |
| 121 | 0 | _netStream.close(); |
| 122 | } | |
| 123 | 0 | catch (error:Error) |
| 124 | { | |
| 125 | //do nothing | |
| 126 | } | |
| 127 | 0 | } |
| 128 | ||
| 129 | private function metaDataHandler(info:Object):void | |
| 130 | { | |
| 131 | 0 | var event:FileLoadingAlgorithmMediaEvent = new FileLoadingAlgorithmMediaEvent(FileLoadingAlgorithmMediaEvent.META_DATA); |
| 132 | 0 | event.metadata = info; |
| 133 | 0 | dispatchEvent(event); |
| 134 | 0 | } |
| 135 | ||
| 136 | private function cuePointHandler(info:Object):void | |
| 137 | { | |
| 138 | 0 | var event:FileLoadingAlgorithmMediaEvent = new FileLoadingAlgorithmMediaEvent(FileLoadingAlgorithmMediaEvent.CUE_POINT); |
| 139 | 0 | event.cuePointData = info; |
| 140 | 0 | dispatchEvent(event); |
| 141 | 0 | } |
| 142 | ||
| 143 | } | |
| 144 | ||
| 145 | } |