18 */ |
18 */ |
19 |
19 |
20 package com.nokia.microedition.media.animation; |
20 package com.nokia.microedition.media.animation; |
21 |
21 |
22 import java.io.IOException; |
22 import java.io.IOException; |
|
23 import javax.microedition.io.Connection; |
|
24 import javax.microedition.io.HttpConnection; |
23 |
25 |
24 import javax.microedition.media.MediaException; |
26 import javax.microedition.media.MediaException; |
25 import javax.microedition.media.protocol.DataSource; |
27 import javax.microedition.media.protocol.DataSource; |
26 |
28 |
27 import org.eclipse.swt.SWTException; |
29 import org.eclipse.swt.SWTException; |
44 // Used to get supported protocols and content type. |
46 // Used to get supported protocols and content type. |
45 private static final String ANIMATION_CONTENT_TYPE = "image/gif"; |
47 private static final String ANIMATION_CONTENT_TYPE = "image/gif"; |
46 private static final String ANIMATION_HTTP_PROTOCOL = "http"; |
48 private static final String ANIMATION_HTTP_PROTOCOL = "http"; |
47 private static final String ANIMATION_HTTPS_PROTOCOL = "https"; |
49 private static final String ANIMATION_HTTPS_PROTOCOL = "https"; |
48 private static final String ANIMATION_FILE_PROTOCOL = "file"; |
50 private static final String ANIMATION_FILE_PROTOCOL = "file"; |
|
51 private static final String CONTENT_TYPE_HEADER = "Content-Type"; |
49 |
52 |
50 /** |
53 /** |
51 * From PlugIn |
54 * From PlugIn |
52 */ |
55 */ |
53 public InternalPlayer createPlayer(DataSource aDataSource) |
56 public InternalPlayer createPlayer(DataSource aDataSource) |
69 player = new AnimationPlayer(aDataSource); |
72 player = new AnimationPlayer(aDataSource); |
70 } |
73 } |
71 } //Since it was not possible to identify the player from content type, identify it from it's header |
74 } //Since it was not possible to identify the player from content type, identify it from it's header |
72 else |
75 else |
73 { |
76 { |
74 // We need only 6 bytes to identify whether it's GIF image data or not. |
77 // This case is for locator for "http://" protocol |
75 // But the problem here is that if we will read even a single byte from stream |
78 // get the httpconnection object, and get the content-type header |
76 // that stream won't be useful for loading the image data through ImageLoader class |
79 // if the content-type header matches to "image/gif" then invoke animation player. |
77 // So better solution is to let the ImageLoader.load(InputStream ) get called |
|
78 // if it successfully load the image, then it means that stream is intended for this player only |
|
79 // otherwise it will throw the SWTException, catch it and return properly |
|
80 try |
80 try |
81 { |
81 { |
82 player = new AnimationPlayer(aDataSource); |
82 Connection con = aDataSource.getConnection(); |
|
83 HttpConnection httpcon = (HttpConnection) con; |
|
84 |
|
85 if (con != null) |
|
86 { |
|
87 String type = httpcon.getHeaderField(CONTENT_TYPE_HEADER); |
|
88 if (type != null) |
|
89 { |
|
90 if (type.equalsIgnoreCase(ANIMATION_CONTENT_TYPE)) |
|
91 { |
|
92 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"AnimationPlayerplayerfactory::createPlayer() content type is mage/gif"); |
|
93 player = new AnimationPlayer(aDataSource); |
|
94 } |
|
95 } |
|
96 } |
83 } |
97 } |
84 catch (SWTException e) |
98 catch (SWTException e) |
85 { |
99 { |
86 // Simply ignore the exception |
100 // Simply ignore the exception |
87 //e.printStackTrace(); |
101 //e.printStackTrace(); |