33 |
33 |
34 /** |
34 /** |
35 * This class is used for playing GIF image animation. This class also |
35 * This class is used for playing GIF image animation. This class also |
36 * implements PlugIn interface which is used from ManagerImpl. |
36 * implements PlugIn interface which is used from ManagerImpl. |
37 * Entire Animation playing is written using eSWT API. |
37 * Entire Animation playing is written using eSWT API. |
38 * There is no call to native. |
38 * There is no call to native. |
39 * |
39 * |
40 */ |
40 */ |
41 public class AnimationPlayerFactory implements PlugIn { |
41 public class AnimationPlayerFactory implements PlugIn |
|
42 { |
42 |
43 |
43 // Used to recognize supported locators. |
44 // Used to recognize supported locators. |
44 // private static final String ANIMATION_FILE_EXTENSION = ".gif"; |
45 // private static final String ANIMATION_FILE_EXTENSION = ".gif"; |
45 |
46 |
46 // Used to get supported protocols and content type. |
47 // Used to get supported protocols and content type. |
47 private static final String ANIMATION_CONTENT_TYPE = "image/gif"; |
48 private static final String ANIMATION_CONTENT_TYPE = "image/gif"; |
48 private static final String ANIMATION_HTTP_PROTOCOL = "http"; |
49 private static final String ANIMATION_HTTP_PROTOCOL = "http"; |
49 private static final String ANIMATION_HTTPS_PROTOCOL = "https"; |
50 private static final String ANIMATION_HTTPS_PROTOCOL = "https"; |
50 private static final String ANIMATION_FILE_PROTOCOL = "file"; |
51 private static final String ANIMATION_FILE_PROTOCOL = "file"; |
51 // There is no need to read the first 6 byte and compare it with following string |
52 // There is no need to read the first 6 byte and compare it with following string |
52 // private static final String ANIMATION_GIF_HEADER="GIF89a"; |
53 // private static final String ANIMATION_GIF_HEADER="GIF89a"; |
53 |
54 |
54 /** |
55 /** |
55 * From PlugIn |
56 * From PlugIn |
56 */ |
57 */ |
57 public InternalPlayer createPlayer(DataSource aDataSource) |
58 public InternalPlayer createPlayer(DataSource aDataSource) |
58 throws MediaException, IOException { |
59 throws MediaException, IOException |
59 final String DEBUG_STR="AnimationPlayerFactory::createPlayer()"; |
60 { |
60 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"+"); |
61 final String DEBUG_STR="AnimationPlayerFactory::createPlayer()"; |
61 InternalPlayer player = null; |
62 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"+"); |
62 String contentType = aDataSource.getContentType(); |
63 InternalPlayer player = null; |
63 // There is no difference in if and else block |
64 String contentType = aDataSource.getContentType(); |
64 // in first if block only checking if the content type is available |
65 // There is no difference in if and else block |
65 // Player is being created in the same way |
66 // in first if block only checking if the content type is available |
66 |
67 // Player is being created in the same way |
67 // First try to create player from content type |
|
68 if (contentType != null){ |
|
69 if(contentType.equals(ANIMATION_CONTENT_TYPE)) { |
|
70 player = new AnimationPlayer(aDataSource); |
|
71 } |
|
72 // else{ |
|
73 // throw new MediaException("Content type not supported: " + contentType); |
|
74 // } |
|
75 } //Since it was not possible to identify the player from content type, identify it from it's header |
|
76 // Is there any need to create player through Locator? |
|
77 |
|
78 else { |
|
79 // We need only 6 bytes to identify whether it's GIF image data or not. |
|
80 // But the problem here is that if we will read even a single byte from stream |
|
81 // that stream won't be useful for loading the image data through ImageLoader class |
|
82 // So better solution is to let the ImageLoader.load(InputStream ) get called |
|
83 // if it successfully load the image, then it means that stream is intended for this player only |
|
84 // otherwise it will throw the SWTException, catch it and return properly |
|
85 try{ |
|
86 player = new AnimationPlayer(aDataSource); |
|
87 }catch(SWTException e){ |
|
88 // Simply ignore the exception |
|
89 e.printStackTrace(); |
|
90 } |
|
91 } |
|
92 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"-"); |
|
93 return player; |
|
94 } |
|
95 |
|
96 /** |
|
97 * @param locator |
|
98 * @return Interplayer object |
|
99 */ |
|
100 public InternalPlayer createPlayer(String locator ){ |
|
101 final String DEBUG_STR="AnimationPlayerFactory::createPlayer(String locator )"; |
|
102 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"+"); |
|
103 InternalPlayer player = null; |
|
104 try{ |
|
105 player = new AnimationPlayer(locator); |
|
106 }catch(SWTException e){ |
|
107 // just ignore it |
|
108 e.printStackTrace(); |
|
109 } |
|
110 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"-"); |
|
111 return player; |
|
112 } |
|
113 |
|
114 |
68 |
115 /** |
69 // First try to create player from content type |
116 * From PlugIn |
70 if (contentType != null) |
117 */ |
71 { |
118 public String[] getSupportedContentTypes(String aProtocol) { |
72 if (contentType.equals(ANIMATION_CONTENT_TYPE)) |
119 String[] types = new String[0]; |
73 { |
120 if (aProtocol == null || aProtocol.equals(ANIMATION_HTTP_PROTOCOL) |
74 player = new AnimationPlayer(aDataSource); |
121 || aProtocol.equals(ANIMATION_HTTPS_PROTOCOL) |
75 } |
122 || aProtocol.equals(ANIMATION_FILE_PROTOCOL)) { |
76 // else{ |
123 types = new String[1]; |
77 // throw new MediaException("Content type not supported: " + contentType); |
124 types[0] = ANIMATION_CONTENT_TYPE; |
78 // } |
125 } |
79 } //Since it was not possible to identify the player from content type, identify it from it's header |
126 return types; |
80 // Is there any need to create player through Locator? |
127 } |
|
128 |
81 |
129 /** |
82 else |
130 * From PlugIn |
83 { |
131 */ |
84 // We need only 6 bytes to identify whether it's GIF image data or not. |
132 public String[] getSupportedProtocols(String aContentType) { |
85 // But the problem here is that if we will read even a single byte from stream |
133 String[] protocols = new String[0]; |
86 // that stream won't be useful for loading the image data through ImageLoader class |
134 if ((aContentType == null) |
87 // So better solution is to let the ImageLoader.load(InputStream ) get called |
135 || aContentType.equals(ANIMATION_CONTENT_TYPE)) { |
88 // if it successfully load the image, then it means that stream is intended for this player only |
136 protocols = new String[3]; |
89 // otherwise it will throw the SWTException, catch it and return properly |
137 protocols[0] = ANIMATION_HTTP_PROTOCOL; |
90 try |
138 protocols[1] = ANIMATION_HTTPS_PROTOCOL; |
91 { |
139 protocols[2] = ANIMATION_FILE_PROTOCOL; |
92 player = new AnimationPlayer(aDataSource); |
140 } |
93 } |
141 // else empty array is returned |
94 catch (SWTException e) |
142 return protocols; |
95 { |
143 } |
96 // Simply ignore the exception |
|
97 e.printStackTrace(); |
|
98 } |
|
99 } |
|
100 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"-"); |
|
101 return player; |
|
102 } |
144 |
103 |
145 /** |
104 /** |
146 * From PlugIn. Empty implementation. |
105 * @param locator |
147 */ |
106 * @return Interplayer object |
148 public void preparePlayer(InternalPlayer aPlayer) throws MediaException { |
107 * @throws IOException |
149 |
108 */ |
150 } |
109 public InternalPlayer createPlayer(String locator) throws IOException |
|
110 { |
|
111 final String DEBUG_STR="AnimationPlayerFactory::createPlayer(String locator )"; |
|
112 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"+"); |
|
113 InternalPlayer player = null; |
|
114 try |
|
115 { |
|
116 player = new AnimationPlayer(locator); |
|
117 } |
|
118 catch (SWTException e) |
|
119 { |
|
120 // For all cases ImageLoader.load throws only SWTException |
|
121 // here we are finding why it has throws this Exception |
|
122 // if it is IOException we need to pass it to caller |
|
123 if (e.getCause().toString().indexOf((IOException.class.getName()))!=-1) |
|
124 throw new IOException(); |
|
125 // if exception is due to any other reason, just ignore it |
|
126 e.printStackTrace(); |
|
127 } |
|
128 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"-"); |
|
129 return player; |
|
130 } |
|
131 |
|
132 |
|
133 /** |
|
134 * From PlugIn |
|
135 */ |
|
136 public String[] getSupportedContentTypes(String aProtocol) |
|
137 { |
|
138 String[] types = new String[0]; |
|
139 if (aProtocol == null || aProtocol.equals(ANIMATION_HTTP_PROTOCOL) |
|
140 || aProtocol.equals(ANIMATION_HTTPS_PROTOCOL) |
|
141 || aProtocol.equals(ANIMATION_FILE_PROTOCOL)) |
|
142 { |
|
143 types = new String[1]; |
|
144 types[0] = ANIMATION_CONTENT_TYPE; |
|
145 } |
|
146 return types; |
|
147 } |
|
148 |
|
149 /** |
|
150 * From PlugIn |
|
151 */ |
|
152 public String[] getSupportedProtocols(String aContentType) |
|
153 { |
|
154 String[] protocols = new String[0]; |
|
155 if ((aContentType == null) |
|
156 || aContentType.equals(ANIMATION_CONTENT_TYPE)) |
|
157 { |
|
158 protocols = new String[3]; |
|
159 protocols[0] = ANIMATION_HTTP_PROTOCOL; |
|
160 protocols[1] = ANIMATION_HTTPS_PROTOCOL; |
|
161 protocols[2] = ANIMATION_FILE_PROTOCOL; |
|
162 } |
|
163 // else empty array is returned |
|
164 return protocols; |
|
165 } |
|
166 |
|
167 /** |
|
168 * From PlugIn. Empty implementation. |
|
169 */ |
|
170 public void preparePlayer(InternalPlayer aPlayer) throws MediaException |
|
171 { |
|
172 |
|
173 } |
151 } |
174 } |