package com.genius.demo;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import com.genius.adapter.GridViewAdapter;
import com.genius.adapter.ListViewAdapter;
import com.genius.interfaces.IOnServiceConnectComplete;
import com.genius.interfaces.IOnSliderHandleViewClickListener;
import com.genius.musicplay.MusicData;
import com.genius.musicplay.MusicPlayMode;
import com.genius.musicplay.MusicPlayState;
import com.genius.service.ServiceManager;
import com.genius.widget.GalleryFlow;
import com.genius.widget.ImageAdapter;
import com.genius.widget.MySlidingDrawer;
import android.R.bool;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.SearchManager.OnDismissListener;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.LevelListDrawable;
import android.opengl.Visibility;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.SeekBar;
import android.widget.SlidingDrawer;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
public class MusicPlayActivity extends Activity implements IOnServiceConnectComplete{
/** Called when the activity is first created. */
private final static String TAG = "MusicPlayActivity";
private final String BROCAST_NAME = "com.genius.musicplay.brocast";
private final static int REFRESH_PROGRESS_EVENT = 0x100;
private final static int ABOUT_DIALOG_ID = 1;
private Handler mHandler;
private UIManager mUIManager;
private ServiceManager mServiceManager;
private MusicTimer mMusicTimer;
private MusicPlayStateBrocast mPlayStateBrocast;
private SDStateBrocast mSDStateBrocast;
private List<MusicData> m_MusicFileList;
private ListViewAdapter mListViewAdapter;
private boolean mIsSdExist = false;
private boolean mIsHaveData = false;
private int mCurMusicTotalTime = 0;
private int mCurPlayMode = MusicPlayMode.MPM_LIST_LOOP_PLAY;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
long time1 = System.currentTimeMillis();
init();
long time2 = System.currentTimeMillis();
Log.i(TAG, "initView cost = " + (time2 - time1));
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
mMusicTimer.stopTimer();
unregisterReceiver(mPlayStateBrocast);
unregisterReceiver(mSDStateBrocast);
mServiceManager.disconnectService();
}
public void onResume()
{
super.onResume();
Log.i(TAG, "onResume");
}
public void onStart()
{
super.onStart();
Log.i(TAG, "onStart");
}
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
switch(id)
{
case ABOUT_DIALOG_ID:
{
Dialog aboutDialog = new AlertDialog.Builder(MusicPlayActivity.this)
.setIcon(R.drawable.about_dialog_icon)
.setTitle(R.string.about_title_name)
.setMessage(R.string.about_content)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK so do some stuff */
}
}).create();
return aboutDialog;
}
default:
break;
}
return null;
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
mUIManager.Back();
}
public void init()
{
mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
switch(msg.what)
{
case REFRESH_PROGRESS_EVENT:
mUIManager.setPlayInfo(mServiceManager.getCurPosition(), mCurMusicTotalTime, null);
break;
default:
break;
}
}
};
mUIManager = new UIManager();
mServiceManager = new ServiceManager(this);
mServiceManager.setOnServiceConnectComplete(this);
mServiceManager.connectService();
mMusicTimer = new MusicTimer(mHandler, REFRESH_PROGRESS_EVENT);
m_MusicFileList = new ArrayList<MusicData>();
mListViewAdapter = new ListViewAdapter(this, m_MusicFileList);
mUIManager.mListView.setAdapter(mListViewAdapter);
mPlayStateBrocast = new MusicPlayStateBrocast();
IntentFilter intentFilter1 = new IntentFilter(BROCAST_NAME);
registerReceiver(mPlayStateBrocast, intentFilter1);
mSDStateBrocast = new SDStateBrocast();
IntentFilter intentFilter2 = new IntentFilter();
intentFilter2.addAction(Intent.ACTION_MEDIA_MOUNTED);
intentFilter2.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
intentFilter2.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
intentFilter2.addAction(Intent.ACTION_MEDIA_EJECT);
intentFilter2.addDataScheme("file");
registerReceiver(mSDStateBrocast, intentFilter2);
}
private List<MusicData> getMusicFileList()
{
List<MusicData> list = new ArrayList<MusicData>();
String[] projection = new String[]{MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.ARTIST};
long time1 = System.currentTimeMillis();
Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI , projection, null, null, null);
if (cursor != null)
{
cursor.moveToFirst();
int colNameIndex = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
int colTimeIndex = cursor.getColumnIndex(MediaStore.Audio.Media.DURATION);
int colPathIndex = cursor.getColumnIndex(MediaStore.Audio.Media.DATA);
int colArtistIndex = cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
int fileNum = cursor.getCount();
for(int counter = 0; counter < fileNum; counter++){
MusicData data = new MusicData();
data.mMusicName = cursor.getString(colNameIndex);
data.mMusicTime = cursor.getInt(colTimeIndex);
data.mMusicPath = cursor.getString(colPathIndex);
data.mMusicAritst = cursor.getString(colArtistIndex);
list.add(data);
cursor.moveToNext();
}
cursor.close();
}
long time2 = System.currentTimeMillis();
Log.i(TAG, "seach filelist cost = " + (time2 - time1));
return list;
}
public void showNoData()
{
Toast.makeText(this, "No Music Data...", Toast.LENGTH_SHORT).show();
}
public void rePlay()
{
if (mIsHaveData == false)
{
showNoData();
}else{
mServiceManager.rePlay();
}
}
public void play(int position)
{
if (mIsHaveDa
荣华富贵8
- 粉丝: 214
- 资源: 7653
最新资源
- (dta格式)各县市区主要社会经济指标(1990-2022年)【重磅,更新】
- JiYuTrainer.rar
- 基于 Echarts.js+PyTorch+Celery+深度学习实现动力电池数据分析系统+项目源码+文档说明
- 【重磅,更新】2014-2024年全国监测站点的15个(空气质量;指标监测数据)
- 最全石头剪刀布数据集下载
- 中期检查+结项报告参考模板+教改类课题+开题报告【重磅,更新!】
- DGA(流量入侵)网络安全数据集
- 【毕业设计/课程设计】免费springbootvue阿博图书馆管理系统源码
- <项目代码>YOLOv8 手机识别<目标检测>
- 【毕业设计/课程设计】免费springboot+vue教师工作量管理系统源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈