1
モバイルデバイスで使用可能なAUDIO(.mp3)ファイルをすべて一覧にしたい。プログラムでカスタム通知着信音を設定する(携帯電話のAUDIOファイルから選択する)
ユーザーはリストから任意のオーディオファイルを選択でき、このアプリケーションの通知音として設定できます。
私は多くの情報源を取り上げましたが、どれも充足できませんでした。
ありがとうございます。
モバイルデバイスで使用可能なAUDIO(.mp3)ファイルをすべて一覧にしたい。プログラムでカスタム通知着信音を設定する(携帯電話のAUDIOファイルから選択する)
ユーザーはリストから任意のオーディオファイルを選択でき、このアプリケーションの通知音として設定できます。
私は多くの情報源を取り上げましたが、どれも充足できませんでした。
ありがとうございます。
まずuは例えばのためretreivedデータにしたいですか何uは、リストビューに設定するかなど、ダイアログ
String extPath = getSecondaryStorage();
if (extPath != null)
{ mySongs_onSystem = findSongs(new File(extPath));
}
else
mySongs_onSystem = findSongs(Environment.getExternalStorageDirectory());
public ArrayList<File> findSongs(File root) {
ArrayList<File> al = new ArrayList<>();
File[] files = root.listFiles();
for (File singleFile : files) {
if (singleFile.isDirectory()) {
al.addAll(findSongs(singleFile));
} else {
if (singleFile.getName().endsWith(".mp3") || singleFile.getName().endsWith(".Mp3") || singleFile.getName().endsWith(".wav")) {
al.add(singleFile);
}
}
}
return al;
}
private String getSecondaryStorage() {
String strSDCardPath = System.getenv("SECONDARY_STORAGE");
if ((strSDCardPath == null) || (strSDCardPath.length() == 0)) {
strSDCardPath = System.getenv("EXTERNAL_SDCARD_STORAGE");
}
//If may get a full path that is not the right one, even if we don't have the SD Card there.
//We just need the "/mnt/extSdCard/" i.e and check if it's writable
if (strSDCardPath != null) {
if (strSDCardPath.contains(":")) {
strSDCardPath = strSDCardPath.substring(0, strSDCardPath.indexOf(":"));
}
File externalFilePath = new File(strSDCardPath);
if (externalFilePath.exists() && externalFilePath.canWrite()) {
return strSDCardPath;
}
}
return null;
}
でそれらを示すことができ、利用可能なすべてのmp3ファイルを取得し、以下のコードを使用して自分の名前を盗ん
このようなforループを使ってすべてのmp3ファイルの名前を調べます。
for (int i = 0; i < mySongs_onSystem.size(); i++) {
//declare a string array in global String[] songNames;
songNames[i] = mySongs_onSystem.get(i).getName().toString().replace(".mp3", "").replace(".Mp3", "").replace(".wav", "");
Log.i("songname", songNames[i]);
}
リスト内のすべての曲の名前を表示し、クリックリスナーを添付するretreived mp3トーンの文字列配列を渡すと、アダプタを一覧表示し、それを添付して
store the uri of the selected mp3
Uri u = Uri.parse(mySongs_onSystem.get(position).getAbsolutePath());
トリガーますカスタムインタフェースを作成します通知が到着してから、このようなメディアプレーヤーを使用して、選択したMP3オーディオを再生する:あなたの応答、その作業が、システムの着信音を(モバイルデバイスDEF取得コードのこの作品のために
mMediaPlayer = new MediaPlayer();
mMediaPlayer = MediaPlayer.create(getApplicationContext(),u);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setLooping(true);
mMediaPlayer.start();
おかげでロイをault着信音は.Mp3形式のファイルではありません)。私はすべての.mp3フォーマットファイル(例:ムービーソングも)をリストにする必要があります。 –
最初のループは、Environment.getExternalStorageDirectory()のように:ArrayList mySongs_onSystem = findSongs(Environment.getExternalStorageDirectory()); –
チャームのように働いた。あなたは私の時間を救った。 Environment.getExternalStorageDirectory()はSdCard0を参照しています。つまり、内部ストレージです。チェックアウトします。ありがとうございました。 –