//assets文件下的mp3播放
try
{
AssetManager assets = getAssets();
AssetFileDescriptor openFd = assets.openFd("music001.mp3");
FileDescriptor fileDescriptor = openFd.getFileDescriptor();
MediaPlayer mediaPlayer = new MediaPlayer();
//下面的表明从哪里播放,播放多久的时间,更专业点 !!!!
// mediaPlayer.setDataSource(fileDescriptor, openFd.getStartOffset(), openFd.getLength());
mediaPlayer.setDataSource(fileDescriptor);
mediaPlayer.prepare();
mediaPlayer.start();
//循环!!!!
mediaPlayer.setLooping(true);
}
catch (IOException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
//sdcard的MP3
//播放应用的资源文件(res/raw/)
try
{
MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.music001);
//不用prepare()设这个就播放不了,直接start()就可以了,调试调试debug
//可能prepare()是针对setDataSource()而言,这里没有setDataSource()就不需要prepare()了
// mediaPlayer.prepare();
mediaPlayer.start();
mediaPlayer.setLooping(true);
}
catch (IllegalStateException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
1.tesseract-ocr训练方法(很牛逼的)
http://my.oschina.net/lixinspace/blog/60124
private void ShowMp3List() {
Cursor cursor = this.getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,//音频的uri
new String[] { MediaStore.Audio.Media.TITLE, //歌曲名称
MediaStore.Audio.Media.DURATION, //歌曲持续的时间
MediaStore.Audio.Media.ARTIST, //歌手
MediaStore.Audio.Media._ID, //歌曲id
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DATA, //歌曲文件路径
MediaStore.Audio.Media.ALBUM_ID }, null, null, null);
if (null != cursor && cursor.getCount() == 0) {
builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.music_list_tell).setPositiveButton(
"aa", null);
ad = builder.create();
ad.show();
listviews.setBackgroundResource(R.drawable.list_empty);
return;
}
cursor.moveToFirst();//验证游标是否为空
while(cursor.moveToNext){
id = cursor.getInt(3);
title= cursor.getString(0);
artist = cursor.getString(2);
path = cursor.getString(5).substring(4);
alltime=(toTime(cursor.getInt(1)));
System.out.println(id+""+title+artist+path+alltime)
}
listview.setAdapter(new SimpleCursorAdapter(this, R.layout.item_listview, cursor, new String[]{MediaStore.Audio.Media._ID
,MediaStore.Audio.Media.ARTIST,MediaStore.Audio.Media.TITLE}, new int[]{R.id.imageView1,R.id.textView1,R.id.textView2}));
}
/////////////////////////////////////////////////////////
MediaStore类是Android平台的多媒体数据库,它包含了音频,视频,图片等所有多媒体文件信息
media 是媒体的意思
MediaStore以ContentProvider的形式向外提供媒体数据库信息。通过Android平台提供的ContentProvider接口,可以方便的访问数据库信息。
MediaStore.Audio.Media类定义了媒体数据库中的歌曲信息
歌曲ID:MediaStore.Audio.Media._ID
歌曲的名称 :MediaStore.Audio.Media.TITLE
MediaStore.Audio.Artists类定义了媒体数据库中的歌手信息
MediaStore.Audio.Albums类定义了媒体数据库中的专辑信息
MediaStore.Audio.Playlists类定义了媒体数据库中的播放列表信息
歌曲文件的路径 :MediaStore.Audio.Media.DATA
歌曲的总播放时长 :MediaStore.Audio.Media.DURATION
歌曲文件的大小 :MediaStore.Audio.Media.SIZE
MediaStore.Audio.Media.DISPLAY_NAME 歌曲id 歌首 歌名(1 周杰伦-爱的怒放.mp3)
audio adj. 听觉的,声音的;音频的
//fragment碎片
package com.wuxifu.musiclist;
import com.example.tabhost002.R;
import com.wuxifu.widget.MyPlayer;
import com.wuxifu.widget.MyService.MyBinder;
import android.database.Cursor;
import android.os.Binder;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
public class SearchaLocalMusicFragment extends ListFragment
{
private Button search;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View inflate = inflater.inflate(R.layout.local_music, null);
search =(Button) inflate.findViewById(R.id.search);
iniSearch();
return inflate;
}
private void iniSearch()
{
}
private MyPlayer myPlayer;
private MyBinder binder;
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
String[] projection=new String[] { MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.ALBUM_ID };
final Cursor cursor = getActivity().getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
if(!cursor.moveToFirst())
{
Log.e("cursor", "cursor为空 ");
return ;
}
setListAdapter(new MusicListAdapter(getActivity(), cursor));
getListView().setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id)
{
if(myPlayer==null || binder==null){
myPlayer = (MyPlayer)getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment1);
binder = myPlayer.getmBinder();
}
//先要让cursor移动要那一行,才能取那一行某列的数据,否则不行的
if( cursor.moveToPosition(position)){
String string=cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
binder.play(string);
}
}
});
}
}
///////////////////////////////
Cursor android.content.ContentResolver.query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
如 select id,name,age from wuxifu where id in (15,20) order by age;
String[] projection=new String[]{"id","name","age"}
//错的::::String selection=new String[]{"id"}
//正确的:::::
String selection=“id in (?,?) ”;
String selectionArgs=new String[]{"110","20"};