作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用一个按钮,我想通过我的服务器从我的手机外部存储目录将音频上传到 soundcloud。我如何从外部存储目录获取歌曲。我如何从外部存储获取路径并使用 http post 上传到服务器。
我想检查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());
}
}
}
}
});
}
如何获取该格式的音频文件以及如何获取发送到服务器上传的路径。
最佳答案
要上传歌曲,您需要获取外部存储目录中音频文件的路径
String[] extensions = { ".mp3",".mp4",".MP3",".MP4"};
然后
String rootpath = Environment.getExternalStorageDirectory().getAbsolutePath();
// get the path of external storage directory
getAllAudioFilePath(rootpath);
然后循环遍历文件夹并获取与扩展名匹配的文件的路径
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());
}
}
}
}
}
}
}
获得文件路径后,您可以使用该路径通过执行 http post 上传到服务器。
另外不要忘记在 list 文件中添加读取权限
关于java - 想要通过我的服务器将音频上传到声音云,我如何检查仅从外部存储目录上传歌曲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19565835/
我是一名优秀的程序员,十分优秀!