[英]Want to upload audio to sound cloud via my server, how can i check to upload songs only from External storage directory
Using a button i want to upload an audio to soundcloud via my server from my phone External storage directory.How can i get the songs from external storage directory. 我想使用按钮从手机外部存储目录通过服务器将音频上传到soundcloud。如何从外部存储目录获取歌曲。 How i will get the path from external storage and upload to server using http post. 我将如何获取来自外部存储的路径并使用http post上传到服务器。
I want to check the formats of mp3,mp4,amr audios. 我想检查mp3,mp4,amr音频的格式。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDbHelper = new GinfyDbAdapter(this);
setContentView(R.layout.upload_audiogallery);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
upload = (Button) findViewById(R.id.btnuplaod);
btnstop = (Button) findViewById(R.id.btnstop);
//Bundle extras = getIntent().getExtras();
mRowId = savedInstanceState != null ? savedInstanceState.getLong(GinfyDbAdapter.CATEGORY_COLUMN_ID4)
: null;
registerButtonListenersAndSetDefaultText();
//for speech to text and recording purpose
setButtonHandlers();
enableButtons(false);
mp = new MediaPlayer();
}
private void registerButtonListenersAndSetDefaultText() {
confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
setResult(RESULT_OK);
Toast.makeText(Uploadaudiogallery.this, getString(R.string.task_saved_message), Toast.LENGTH_SHORT).show();
finish();
}
});
upload .setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getFromSdcard();
}
public void getFromSdcard()
{
File file= new File(android.os.Environment.getExternalStorageDirectory().getPath());
if (file.isDirectory())
{
listFile = file.listFiles();
String[] Patternmp3 = {".3gp",".mp3",".amr",".mp4" };
for (int i = 0; i < listFile.length; i++)
{
if (listFile[i].getName().endsWith(Patternmp3)){
f.add(listFile[i].getAbsolutePath());
}
}
}
}
});
}
How can i get the audio files with the format and how can i get the path to send to the server to upload . 如何获取具有该格式的音频文件,以及如何获取发送到服务器上载的路径。
To upload a song you need to get the path of the audio file in external storage directory 要上传歌曲,您需要在外部存储目录中获取音频文件的路径
String[] extensions = { ".mp3",".mp4",".MP3",".MP4"};
Then 然后
String rootpath = Environment.getExternalStorageDirectory().getAbsolutePath();
// get the path of external storage directory
getAllAudioFilePath(rootpath);
Then loop through the folders and get the path of the files that matches the extension 然后遍历文件夹并获取与扩展名匹配的文件的路径
private void getAllAudioFilePath(String rootFolder) {
File file = new File(rootFolder);
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null && files.length > 0) {
for (File f : files) {
if (f.isDirectory()) {
loadAllImages(f.getAbsolutePath());
} else {
for (int i = 0; i < extensions.length; i++) {
if (f.getAbsolutePath().endsWith(extensions[i])) {
Log.i("Song files paths....",""+f.getAbsolutePath());
}
}
}
}
}
}
}
Once you have the path of the files you can use the same to upload to a server by executing a http post. 一旦有了文件的路径,就可以通过执行http发布来使用文件路径将其上传到服务器。
Also don't forget to add read permission in the manifest file 同样不要忘记在清单文件中添加读取权限
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.