开发者

how to remove ".mp3" from "xxx.mp3" string

i want to make a music player, i have a problem to toast file name because it always includes the extension(".mp3")

does anyone know how to remove those extension?

this is my code

try {
    if (mMediaPlayer.isPlaying()) {
        mMedi开发者_C百科aPlayer.reset();
    }
    mMediaPlayer.setDataSource(filename);
    mMediaPlayer.prepare();
    mMediaPlayer.start();
    Toast.makeText(getApplicationContext(), nama , Toast.LENGTH_LONG).show();
} catch (Exception e) {
}

and

music_column_index=
    musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME);
musiccursor.moveToPosition(position);
nama = musiccursor.getString(music_column_index);

i want to make it toast "xx" not "xx.mp3"


String name = "Jai_Ho.mp3"
String nameWithoutExtension = name.subString(0,name.lastIndexOf("."));

See Also

  • Document


just filename = filename.replaceFirst("\\.mp3$", "");


    String s = "xx.mp3";
    s= s.replace(".mp3","");
    System.out.println(s);


I'm not certain, but does nama give you the xx.mp3? If so:

nama = musiccursor.getString(music_column_index).substring(0, musiccursor.getString(music_column_index).lastIndexOf("."));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜