简体   繁体   English

想要通过我的服务器将音频上传到声音云,如何检查仅从外部存储目录上传歌曲

[英]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.

相关问题 如何通过我的应用程序在soundcloud中上传音频,我也想将该ID发送到我的服务器 - How to upload audio in soundcloud via my app and i want to send that id also to my server 通过appengine将文件上传到Google云端存储 - Upload File to Google Cloud Storage via appengine 如何在不使用GAE的情况下将文件上传到Google云存储中 - how can i upload a file in google cloud storage without using GAE 如何从Android客户端将媒体文件(图像或mp3歌曲)上传到Java服务器 - How to upload media files(images or mp3 songs ) to java server from android client 如何将目录上传到FTP? - How can I upload directory to FTP? 如何在 Google Cloud Storage 中上传批处理对象? - How to upload batch objects in Google Cloud Storage? 如何将大文件上传到GCP云存储? - How to upload a large file into GCP Cloud Storage? 如何获得服务器的响应,例如“上传成功” - How can I get a response from the server such as “Upload Successful” Android如何从sdcard上传文件到SFTP服务器? - How can i upload file from sdcard to SFTP server in Android? 通过Google App Engine(JAVA)将文件(图像或视频)从JSP上传到Google云存储 - Upload File (image or video) from JSP to google cloud storage via Google app engine(JAVA)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM