Slide 1

Slide 1 text

MediaStore Keishin Yokomaku @ Drivemode, Inc. kyobashi.dex #3

Slide 2

Slide 2 text

@KeithYokoma • Keishin Yokomaku at Drivemode, Inc. • Work • Android apps • Android Training and its publication • Like • Bicycle, Photography, Tumblr and Motorsport • ·͓ͨલ͔

Slide 3

Slide 3 text

MediaStore

Slide 4

Slide 4 text

MediaStore is Կ • ୺຤ʹอଘ͞ΕͨԻָɾը૾ɾಈըͷ؅ཧΛ͢Δσʔλϕʔε • MediaStore.Audio, MediaStore.Images, MediaStore.Video • Uri ͱ֤छͷΧϥϜ৘ใ͕ఏڙ͞Ε͍ͯΔ • EXTERNAL_CONTENT_URI ͱ INTERNAL_CONTENT_URI • MediaStore.Audio.Media ΍ MediaStore.Images.Media ͳͲ

Slide 5

Slide 5 text

MediaStore is Կ public class SampleActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Cursor albums = null; try { albums = getContentResolver().query( MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null, null, null, null); } finally { if (albums != null) albums.close(); } } }

Slide 6

Slide 6 text

MediaStore is Կ public class SampleActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Cursor albums = null; try { albums = getContentResolver().query( MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null, null, null, null); } finally { if (albums != null) albums.close(); } } }

Slide 7

Slide 7 text

Ṗଟ͖ MediaStore • ऴΘΒ͵ѱ͖͠ܧঝͷ࿈࠯ͱΧϥϜͷࠞಱ • ΧϥϜ৘ใʹܧঝؔ܎͸͋Δ͕ɺ਌Ͱఆٛ͞ΕͨΧϥϜ৘ใ͕ࢠͰ΋࢖ ͑Δͱ͸ݶΒͳ͍ • MediaColumns ͸Իָɾը૾ɾಈը͢΂ͯͷڞ௨ͷΧϥϜ৘ใΛ࣋ͬ ͍ͯΔ͕ৗʹͦͷΧϥϜ৘ใ͕࢖͑Δͱ͸ݶΒͳ͍ • ΧϥϜͷ੍໿͕ϫΧϥφΠ • Javadoc ʹॻ͍ͯͳ͍ͷͰ࢖ͬͯΈͯॳΊͯؾ͕ͭ͘

Slide 8

Slide 8 text

Ṗଟ͖ MediaStore • Ҿ͖ํ͕͍·͍ͪෆ໌ͳσʔλ • ద੾ͳ Uri Λ࢖Θͳ͍ͱऔͬͯ͜Εͳ͍ΧϥϜ͕͋Δ • શΧϥϜΛऔಘͨ͠ͱ͖ʹԿ͕ೖͬͯΔ͔ϫΧϥφΠ • υΩϡϝϯτʹͳ͍ Uri ͕͋ͬͨΓɺͦΕΛ࢖Θͳ͍ͱ໘౗͍࣮͘͞૷ Λ͠ͳ͍ͱ͍͚ͳ͔ͬͨΓ͢Δ • ΄΅ϊʔίϝϯτɾυΩϡϝϯτ

Slide 9

Slide 9 text

Ṗଟ͖ MediaStore • ੲͷΪϟϥϦʔΞϓϦ͸ MediaStore ʹ SQL ΠϯδΣΫγϣϯΛ͍ͯͨ͠ • ࣸਅΛσΟϨΫτϦ͝ͱʹ෼͚Δ֓೦͸ը૾ͻͱͭͻͱͭͷσʔλʹ݁ ߹͍ͯ͠Δ • άϧʔϓԽ͠ͳ͍ͱσΟϨΫτϦͷ֓೦͕ͱΓͩͤͳ͍ • ContentResolver ʹάϧʔϓԽͷ API ͸ͳ͍ • SQL ΠϯδΣΫγϣϯͰରԠ͢Δߥۀ

Slide 10

Slide 10 text

΋͏ŵŧƄແཧɻϦεΧ͠ΐ……

Slide 11

Slide 11 text

Ͳ͏͢Δ • ະ஌ͳ෦෼͕ଟ͍ͱ͸͍͑ɺ෼͔ͬͯ͠·͑͹Ҿ͖ํ͸ҰఆʹͳΔ • ϘΠϥʔϓϨʔτԽ͢Δͷ͸໨ʹݟ͍͑ͯΔ • Cursor Λͦͷ··࢖͏ͷ͸ؾ͕໓ೖΔ • ·ͩ ContentResolver Ͱফ໣͢Δͭ΋Γͳͷʁ • ੍໿৘ใ͸ϝιουͷҾ਺ͱͯ͠ඞͣࢦఆ͢ΔΑ͏ʹͯ͠ݟ͑ΔԽ͍ͨ͠

Slide 12

Slide 12 text

΋͏ŵŧƄແཧɻϥΠϒϥϦʹ͠ΐ

Slide 13

Slide 13 text

MediaFacade

Slide 14

Slide 14 text

MediaFacade • https://github.com/Drivemode/MediaFacade • ·ͩϦϦʔε͸͍ͯ͠ͳ͍ • Ұ௨ΓԻָɾը૾ɾಈըͷ API ͕ͦΖ͍ͬͯΔ • ΈΜͳେ޷͖γϯάϧτϯ • Cursor ͷྑ͞Λ׆͔ͭͭ͠ɺσʔλ΁ͷΞΫηεΛ͠΍͘͢

Slide 15

Slide 15 text

ྫɿΞϧόϜ(Իָ)ͷऔಘ public class SampleActivity extends Activity { private AudioFacade facade; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); facade = AudioFacade.getInstance(this); Cursor albums = null; try { albums = facade.album().fetchAlbum(); // do whatever you like with the album metadata } finally { if (albums != null) albums.close(); } } }

Slide 16

Slide 16 text

ྫɿΞϧόϜ(Իָ)ͷऔಘ public class SampleActivity extends Activity { private AudioFacade facade; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); facade = AudioFacade.getInstance(this); Cursor albums = null; try { albums = facade.album().fetchAlbum(); // do whatever you like with the album metadata } finally { if (albums != null) albums.close(); } } }

Slide 17

Slide 17 text

ྫɿΞϧόϜ(Իָ)ͷऔಘ public class SampleActivity extends Activity { private AudioFacade facade; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); facade = AudioFacade.getInstance(this); Cursor albums = null; try { albums = facade.album().fetchAlbum(); // do whatever you like with the album metadata } finally { if (albums != null) albums.close(); } } }

Slide 18

Slide 18 text

ྫɿΞϧόϜ(Իָ)ͷऔಘ AlbumCursor albums = null; try { albums = facade.album().fetchAlbum(); while (albums.moveToNext()) { long id = albums.id(); String name = albums.displayName(); // …… } } finally { if (albums != null) albums.close(); }

Slide 19

Slide 19 text

ྫɿΞϧόϜ(Իָ)ͷऔಘ AlbumCursor albums = null; try { albums = facade.album().fetchAlbum(); while (albums.moveToNext()) { long id = albums.id(); String name = albums.displayName(); // …… } } finally { if (albums != null) albums.close(); }

Slide 20

Slide 20 text

Α͞ • ContentResolver ܦ༝Ͱͷૢ࡞Λϥοϓ͠ɺԿΛҾ͖͍͔ͨ͝ͱʹϝιο υ͕Θ͔Ε͍ͯΔͷͰαοͱ࢖͑Δ • ୯७ͳߏ଄ͳͷͰ؆୯ʹ Rx ͳͲͰϥοϓͰ͖Δ • طଘͷ Android ͷ API ͱͷ਌࿨ੑ͸΄΅ͦͷ··(Loader ͸͋·Γߟ͑ͯ ͍ͳ͍) • औ͖ͬͯͨ Cursor ͔ΒϝιουҰൃͰͱΓ͍ͨσʔλʹΞΫηεͰ͖Δ • ൥Θ͍͠ΧϥϜ໊ࢦఆ͔ΒαϤφϥʂ

Slide 21

Slide 21 text

ॿ͚ͯཉ͍͜͠ͱ • ୺຤ґଘ͕͋Δͧ • ṖͷΧϥϜ͕ੜ͑ͯͨΓɺṖͷσʔλ͕ೖ͍ͬͯͨΓ • ΧϥϜ͕૿͍͑ͯΔ෼ʹ͸େͯ͠ࠔΒͳ͍͕ɺຊདྷΧϥϜʹೖ͍ͬͯΔ ͸ͣͷͳ͍σʔλ͕ೖ͍ͬͯΔͱ͖͸ࠔΔ • OSS ΁ίϯτϦϏϡʔτνϟϯεʂ

Slide 22

Slide 22 text

MediaStore Keishin Yokomaku @ Drivemode, Inc. kyobashi.dex #3