我現在有一個問題,我嘗試在手機上創建一個音樂應用程式。現在我可以看到我的檔案歌曲但應用程式中顯示的名稱是檔案地址。如果我想在這個應用程式中播放檔案音樂。我需要添加什么代碼才能獲取音樂名稱并在手機上播放?非常感謝
@Override
public void onClick(View view) {
mp.pause();
play.setEnabled(true);
stop.setEnabled(true);
pause.setEnabled(false);
}
});
stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mp != null) {
mp.stop();
try {
mp.prepare();
} catch (IOException e) {
e.printStackTrace();
}
//mp.release()
play.setEnabled(true);
play.setEnabled(true);
stop.setEnabled(false);
}
}
});
send.setOnClickListener(new View.OnClickListener() {
//List<Intent> intentShareList = new ArrayList<Intent>();
@Override
public void onClick( View view ) {
msgs = msg.getText().toString();
System.out.print("msgs " msgs);
// make line message
Log.d(TAG, "Txt " msgs);
Intent shareIntent = new Intent();
String userId = "";
String sendText = "line://ti/p/~" userId;
//shareIntent = null;
try {
shareIntent = Intent.parseUri(sendText,
Intent.URI_INTENT_SCHEME);
} catch (URISyntaxException e) {
e.printStackTrace();
}
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_TEXT,msgs);
shareIntent.setType("text/plain");
startActivity(shareIntent);
}
});
} 和
public class Songs {
//private
private String songTitle;
private String songAddress;
public Songs(String title){
//songID = id;
songTitle = title;
}
/*public long getSongID(){
return songId;
*/
public String getSongTitle(){
return songTitle;
}
}
uj5u.com熱心網友回復:
現在我可以看到我的檔案歌曲但是應用程式中顯示的名稱是 檔案地址
我認為您指的是檔案的“路徑”,例如:
/storage/emulated/0/song.mp3(Unix風格路徑)
C:\Songs\song.mp3(視窗風格路徑)
如果您想決議(找出)檔案的名稱,請使用以下代碼:
String filePath = "/storage/emulated/0/song.mp3";
File f = new File(filePath);
String fileName = f.getName();
// fileName == "song.mp3"
在你的情況下:
public class Songs {
private String title; // renamed from "songTitle"
private String path; // renamed from "songAddress"
private String fileName; // the file name of the song
public Songs(String title, String path){
this.title = title;
this.path = path;
File file = new File(path);
String fileName = f.getName();
this.fileName = fileName;
}
public String getTitle(){
return title;
}
public String getPath(){
return path;
}
public String getFileName(){
return fileName;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/435789.html
標籤:javascript 爪哇 安卓工作室
