|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This class has been implemented for playing the GIF animation |
|
15 * Earlier implementation were dependent on native API, but now AnimationPlayer |
|
16 * will be not use any native code, and all the implementation here is using eswt API |
|
17 * |
|
18 */ |
|
19 |
|
20 package com.nokia.microedition.media.animation; |
|
21 |
|
22 import java.io.IOException; |
|
23 |
|
24 import javax.microedition.media.MediaException; |
|
25 import javax.microedition.media.protocol.DataSource; |
|
26 |
|
27 import org.eclipse.swt.SWTException; |
|
28 |
|
29 import com.nokia.microedition.media.InternalPlayer; |
|
30 import com.nokia.microedition.media.Locator; |
|
31 import com.nokia.microedition.media.PlugIn; |
|
32 |
|
33 /** |
|
34 * This class is used for playing GIF image animation. This class also |
|
35 * implements PlugIn interface which is used from ManagerImpl. |
|
36 * Entire Animation playing is written using eSWT API. |
|
37 * There is no call to native. |
|
38 * |
|
39 */ |
|
40 public class AnimationPlayerFactory implements PlugIn { |
|
41 |
|
42 // Used to recognize supported locators. |
|
43 // private static final String ANIMATION_FILE_EXTENSION = ".gif"; |
|
44 |
|
45 // Used to get supported protocols and content type. |
|
46 private static final String ANIMATION_CONTENT_TYPE = "image/gif"; |
|
47 private static final String ANIMATION_HTTP_PROTOCOL = "http"; |
|
48 private static final String ANIMATION_HTTPS_PROTOCOL = "https"; |
|
49 private static final String ANIMATION_FILE_PROTOCOL = "file"; |
|
50 // There is no need to read the first 6 byte and compare it with following string |
|
51 // private static final String ANIMATION_GIF_HEADER="GIF89a"; |
|
52 |
|
53 /** |
|
54 * From PlugIn |
|
55 */ |
|
56 public InternalPlayer createPlayer(DataSource aDataSource) |
|
57 throws MediaException, IOException { |
|
58 final String DEBUG_STR="AnimationPlayerFactory::createPlayer()"; |
|
59 System.out.println(DEBUG_STR+"+"); |
|
60 InternalPlayer player = null; |
|
61 System.out.println(DEBUG_STR+"data source object is "+aDataSource); |
|
62 String contentType = aDataSource.getContentType(); |
|
63 System.out.println(DEBUG_STR+"Content type is "+contentType); |
|
64 // There is no difference in if and else block |
|
65 // in first if block only checking if the content type is available |
|
66 // Player is being created in the same way |
|
67 |
|
68 // First try to create player from content type |
|
69 if (contentType != null){ |
|
70 if(contentType.equals(ANIMATION_CONTENT_TYPE)) { |
|
71 player = new AnimationPlayer(aDataSource); |
|
72 System.out.println(DEBUG_STR+"Player created from content type"+contentType); |
|
73 } |
|
74 // else{ |
|
75 // throw new MediaException("Content type not supported: " + contentType); |
|
76 // } |
|
77 } //Since it was not possible to identify the player from content type, identify it from it's header |
|
78 // Is there any need to create player through Locator? |
|
79 |
|
80 else { |
|
81 // We need only 6 bytes to identify whether it's GIF image data or not. |
|
82 // But the problem here is that if we will read even a single byte from stream |
|
83 // that stream won't be useful for loading the image data through ImageLoader class |
|
84 // So better solution is to let the ImageLoader.load(InputStream ) get called |
|
85 // if it successfully load the image, then it means that stream is intended for this player only |
|
86 // otherwise it will throw the SWTException, catch it and return properly |
|
87 try{ |
|
88 player = new AnimationPlayer(aDataSource); |
|
89 System.out.println(DEBUG_STR+"Player created from content type"); |
|
90 }catch(SWTException e){ |
|
91 // Simply ignore the exception |
|
92 e.printStackTrace(); |
|
93 } |
|
94 } |
|
95 System.out.println(DEBUG_STR+"-"); |
|
96 return player; |
|
97 } |
|
98 |
|
99 /** |
|
100 * @param locator |
|
101 * @return Interplayer object |
|
102 */ |
|
103 public InternalPlayer createPlayer(String locator ){ |
|
104 final String DEBUG_STR="AnimationPlayerFactory::createPlayer(String locator )"; |
|
105 System.out.println(DEBUG_STR+"+"); |
|
106 InternalPlayer player = null; |
|
107 try{ |
|
108 player = new AnimationPlayer(locator); |
|
109 }catch(SWTException e){ |
|
110 // just ignore it |
|
111 e.printStackTrace(); |
|
112 } |
|
113 System.out.println(DEBUG_STR+"returning player "+player); |
|
114 System.out.println(DEBUG_STR+"-"); |
|
115 return player; |
|
116 } |
|
117 |
|
118 |
|
119 /** |
|
120 * From PlugIn |
|
121 */ |
|
122 public String[] getSupportedContentTypes(String aProtocol) { |
|
123 String[] types = new String[0]; |
|
124 if (aProtocol == null || aProtocol.equals(ANIMATION_HTTP_PROTOCOL) |
|
125 || aProtocol.equals(ANIMATION_HTTPS_PROTOCOL) |
|
126 || aProtocol.equals(ANIMATION_FILE_PROTOCOL)) { |
|
127 types = new String[1]; |
|
128 types[0] = ANIMATION_CONTENT_TYPE; |
|
129 } |
|
130 return types; |
|
131 } |
|
132 |
|
133 /** |
|
134 * From PlugIn |
|
135 */ |
|
136 public String[] getSupportedProtocols(String aContentType) { |
|
137 String[] protocols = new String[0]; |
|
138 if ((aContentType == null) |
|
139 || aContentType.equals(ANIMATION_CONTENT_TYPE)) { |
|
140 protocols = new String[3]; |
|
141 protocols[0] = ANIMATION_HTTP_PROTOCOL; |
|
142 protocols[1] = ANIMATION_HTTPS_PROTOCOL; |
|
143 protocols[2] = ANIMATION_FILE_PROTOCOL; |
|
144 } |
|
145 // else empty array is returned |
|
146 return protocols; |
|
147 } |
|
148 |
|
149 /** |
|
150 * From PlugIn. Empty implementation. |
|
151 */ |
|
152 public void preparePlayer(InternalPlayer aPlayer) throws MediaException { |
|
153 // tone does not extend existing players |
|
154 } |
|
155 } |