《mastering_the_android_media_framework》由会员分享,可在线阅读,更多相关《mastering_the_android_media_framework(56页珍藏版)》请在金锄头文库上搜索。
1、 Noisy Androids Mastering the Android Media Framework Dave Sparks 27-May-2009 3 Agenda Frank Lloyd Android: Media Framework architecture Sweet Android: Whats new in Cupcake V1.5? Busted Android: Common problems Curious Android: Q import android.media.AudioManager; . public void onCreate(Bundle icicl
2、e) super.onCreate(icicle); setVolumeControlStream(AudioManager.STREAM_MUSIC); . 30 Problem: Unable to play file from resource? MediaPlayer mp = new MediaPlayer(); try mp.setDataSource(“res:com.myapp.raw.test”); mp.prepare(); catch (IOException e) Log.e(“Error ” + e.print() + “ opening media player”)
3、; 31 Solution: Use AssetFileDescriptor AssetFileDescriptor afd = context.getResources().openRawResourceFd(resId); set.DataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength(); afd.close(); 32 Problem: Out of MediaPlayers! MediaPlayer mpArray = new Object50; for (int i = 0; i 50; i+)
4、 MediaPlayer mp = MediaPlayer.create(soundNamei); mp.prepare(); mpArrayi = mp; 33 Solution: Reuse MediaPlayer Call release() and set to null Or call reset(), then setDataSource() Limit to 2 or 3 maximum 34 Problem: CPU Overloaded MediaPlayer sound1 = new MediaPlayer(); MediaPlayer sound2 = new Media
5、Player(); MediaPlayer sound3 = new MediaPlayer(); / call setDataSource, prepare, etc. . / later on. sound1.start(); sound2.start(); sound3.start(); . / CPU is bogging down here. 35 Solution: Use SoundPool import android.media.SoundPool; import android.media.AudioSystem; Context context = getApplicat
6、ionContext(); sp = new SoundPool(maxStreams, AudioSystem.STREAM_MUSIC, 0); int snd1 = sp.load(context, res.Raw.pow); int snd2 = sp.load(context, res.Raw.blam); int snd2 = sp.load(context, res.Raw.biff); . sp.play(snd1, leftVol, rightVol, priority, loop, rate); . sp.play(snd2, leftVol, rightVol, prio
7、rity, loop, rate); . sp.play(snd3, leftVol, rightVol, priority, loop, rate); Q map.setCenter(new GLatLng(37.442, -122.142), 13); var bounds = map.getBounds(); var lngSpan = northEast.lng() - southWest.lng(); var latSpan = northEast.lat() - southWest.lat(); for (var i = 0; i 10; i+) var point = new G
8、LatLng(southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random(); map.addOverlay(new GMarker(point); 49 Color Palette Primary Neutral Picker R 0 G 102 B 204 R 125 G 125 B 125 R 0 G 138 B 53 R 255 G 0 B 0 R 255 G 211 B 25 50 Graphic Element Styles and Arrows 51 Pie Chart Ex
9、ample Chart title or subtitle placeholder Google 48% MSN 19% Yahoo 33% Source: Insight Express Survey of 1000 home Internet users (June 2004) 52 Column Chart Example Chart is positioned to the left of the text box aligned to left guide Depending on size of chart and amount of text content, positioni
10、ng of text box may vary Font size can be decreased Source: Insight Express Survey of 1000 home Internet users (June 2004) 0 12.5 25.0 37.5 50.0 GoogleYahooMSN Chart title or subtitle placeholder 53 Line Chart Example 0% 225% 450% 675% 900% 123456789101112 Chart is positioned to the left of the text
11、box aligned to left guide Depending on size of chart and amount of text content, positioning of text box may vary Font size can be decreased Source: Insight Express Survey of 1000 home Internet users (June 2004) Chart title or subtitle placeholder 54 Attract Customers Build Customer Loyalty Develop
12、New Revenue Streams Monetize Your Digital Assets Monetize Your Digital Assets WebSearch AdSense for Search AdSense for Content Matrix Example Chart title or subtitle placeholder Segue Slide “The perfect search engine would understand exactly what you mean and give back exactly what you want.” Larry Page, Google Co-Founder