簡體   English   中英

想要通過我的服務器將音頻上傳到聲音雲,如何檢查僅從外部存儲目錄上傳歌曲

[英]Want to upload audio to sound cloud via my server, how can i check to upload songs only from External storage directory

我想使用按鈕從手機外部存儲目錄通過服務器將音頻上傳到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發布來使用文件路徑將其上傳到服務器。

同樣不要忘記在清單文件中添加讀取權限

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM