Android 安卓:找到同名歌曲?

Android 安卓:找到同名歌曲?,android,eclipse,android-intent,Android,Eclipse,Android Intent,我试图播放的歌曲形式的设备,其中部分名称的歌曲由用户给出。 比如,如果歌曲名为“demosong.mp3”,如果用户在文本框中插入“demo”,则必须播放“demosong.mp3” 我的代码如下: fileList=getfile(new File(Environment.getExternalStorageDirectory() .getAbsolutePath())); String s

我试图播放的歌曲形式的设备,其中部分名称的歌曲由用户给出。 比如,如果歌曲名为“demosong.mp3”,如果用户在文本框中插入“demo”,则必须播放“demosong.mp3”

我的代码如下:

    fileList=getfile(new File(Environment.getExternalStorageDirectory()
                        .getAbsolutePath()));
            String  
          ss=fileList.toString();
          chk="Song Name i.e.demo";
          String direc,totpath,root1;
          root1=file21;
          direc="";
          name="";  
          String fla="True";
                for (int i = 0; i < fileList.size(); i++) {
                    TextView textView = new TextView(this); 



                    if (fileList.get(i).isDirectory()) {
                        direc="";
                        direc=fileList.get(i).getName();

                        //textView.setTextColor(Color.parseColor("#FF0000"));
                    }
                    else
                    {

                        name=direc+"//"+fileList.get(i).getName();
                        String  name1=name.toLowerCase();

                            if(name1.contains(chk))
                            {

                                String pth,nnn;




                                    Uri myUri11 = Uri.parse(pth);
                                 mPlayer = new MediaPlayer();
                                    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                                    try 
                                    {
                                        mPlayer.setDataSource(getApplicationContext(),myUri11);
                                    } catch (IllegalArgumentException e) {
                                        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
                                    } catch (SecurityException e) {
                                        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
                                    } catch (IllegalStateException e) {
                                        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
                                    } catch (IOException e) 
                                    {
                                        e.printStackTrace();
                                    }
                                    try {
                                        mPlayer.prepare();
                                    } catch (IllegalStateException e) {
                                        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
                                    } catch (IOException e) {
                                        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
                                    }
                                    mPlayer.start();


                                    break;
                            }
                             else if(r[0].compareTo("stop")==0){

                                mPlayer.stop();
                                mPlayer.release();

                      }
                      else if(r[0].compareTo("pause")==0){

                          mPlayer.pause();                
                          mPlayer.release();
                          }


                    }





                }


                }


          }
          catch (Exception e) {
                // TODO: handle exception
            }
    }
fileList=getfile(新文件(Environment.getExternalStorageDirectory())
.getAbsolutePath());
一串
ss=fileList.toString();
chk=“歌曲名称即演示”;
字符串direc,totpath,root1;
root1=file21;
direc=“”;
name=“”;
字符串fla=“True”;
对于(int i=0;i
检查文件扩展名的代码

public ArrayList<File> getfile(File dir) {
    File listFile[] = dir.listFiles();
    if (listFile != null && listFile.length > 0) {
        for (int i = 0; i < listFile.length; i++) {

            if (listFile[i].isDirectory()) {
                fileList.add(listFile[i]);
                getfile(listFile[i]);

            } else {
                if ( listFile[i].getName().endsWith(".mp3"))

                {
                    fileList.add(listFile[i]);
                }
            }

        }
    }
    return fileList;
}
public ArrayList getfile(文件目录){
文件listFile[]=dir.listFiles();
if(listFile!=null&&listFile.length>0){
for(int i=0;i
}


谢谢您,不要使用名称1。包含(chk)请使用名称1。startsWith(chk)有什么问题?是否匹配?是否会进入“如果”状态?你到底在文本框中输入了什么?我给出了我想播放的歌曲的一些文本,即:如果歌曲是“生活艺术Om.mp3,如果我在文本框中输入“生活艺术”,那么歌曲必须播放,但如果目录中没有包含歌曲的输入内容,那么歌曲将进入if状态。这里有问题吗?