1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.musicplayer; 18 19 import android.os.AsyncTask; 20 21 /** 22 * Asynchronous task that prepares a MusicRetriever. This asynchronous task essentially calls 23 * {@link MusicRetriever#prepare()} on a {@link MusicRetriever}, which may take some time to 24 * run. Upon finishing, it notifies the indicated {@MusicRetrieverPreparedListener}. 25 */ 26 public class PrepareMusicRetrieverTask extends AsyncTask<Void, Void, Void> { 27 MusicRetriever mRetriever; 28 MusicRetrieverPreparedListener mListener; 29 30 public PrepareMusicRetrieverTask(MusicRetriever retriever, 31 MusicRetrieverPreparedListener listener) { 32 mRetriever = retriever; 33 mListener = listener; 34 } 35 36 @Override 37 protected Void doInBackground(Void... arg0) { 38 mRetriever.prepare(); 39 return null; 40 } 41 42 @Override 43 protected void onPostExecute(Void result) { 44 mListener.onMusicRetrieverPrepared(); 45 } 46 47 public interface MusicRetrieverPreparedListener { 48 public void onMusicRetrieverPrepared(); 49 } 50 } 51