对歌曲就行修改

Author Avatar ZTFtrue 发表于 • 2018年03月28日 16:55 • 共 • 392 • 次浏览

package com.ztftrue.application;

import android.media.MediaMetadataRetriever; import android.os.Bundle; import android.os.Environment; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.Toast;

import java.io.File;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    readfile(Environment.getExternalStorageDirectory().toString() + "/Music");
}

String stuf;

public void readfile(String filepath) {
    File file = new File(filepath);
    if (!file.isDirectory()) {
        Log.d("log", "文件");
        Log.d("log", "path=" + file.getPath());
        Log.d("log", "absolutepath=" + file.getAbsolutePath());
        Log.d("log", "name=" + file.getName());
    } else if (file.isDirectory()) {
        Log.d("log", "文件夹");
        String[] filelist = file.list();

        for (int i = 0; i < filelist.length; i++) {
            File readfile = new File(filepath + "/" + filelist[i]);
            if (!readfile.isDirectory()) {
                MediaMetadataRetriever mmr = new MediaMetadataRetriever();
                mmr.setDataSource(readfile.toString());
                String title = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
                String zuozhe = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST);
                String mimie = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE);
                String mp3 = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS);
                String s = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DISC_NUMBER);
                stuf = filelist[i].substring(filelist[i].lastIndexOf('.'), filelist[i].length());
                if (stuf.equals(".MP3"))
                    stuf = ".mp3";

                String a = filepath + "/" + title + "-" + zuozhe + stuf;
                File newFile = new File(a);
                readfile.renameTo(newFile);
            } else if (readfile.isDirectory()) {
                readfile(filepath + "\\" + filelist[i]);
            }
        }

    }
    Toast.makeText(MainActivity.this, "suss", Toast.LENGTH_LONG).show();

}

}

最后编辑于 • 2018年03月28日 16:55 •  

你尚未登录,无法进行回复。