简体   繁体   中英

Downloading .mp3 files to my app via FTP changes files' quality

My small game app uses FTP to download some .mp3 sounds. The problem with quality occurs since I upgraded from the free webhosting. Sounds are played with some noise, similiar to that one when your TV has signal problems. I didn't make any changes to the code and the file is downloading properly, the file size, duration and bitrate are not getting changed after the download.

What I've already checked:

  • problem occurs on all devices
  • sounds played in browser (both PC and mobile) are OK
  • sounds downloaded from site to PC or mobile are OK
  • sounds downloaded previously from the free webhosting played on the same app screen (or anywhere else in the app) are OK
  • old sounds (working properly in app) reuploaded to a new site and redownloaded by app create the same problem

So, literally only files downloaded by my app from a new server are bad quality.

// This is only a part of code, but it's working correctly for more than 2 years now

for (FTPFile file : ftpFiles) {
    String name = file.getName();
    OutputStream outputStream;

    if (name.endsWith(".zip") && Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        // Application auto-update
        if (Build.VERSION.SDK_INT >= 23 && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) 
        { 
            continue;
        }
    outputStream = new FileOutputStream(path);
    editor.putBoolean("newAppAvailable", true).apply();
    } else {
        File localFile = new File(LoadingScreen.this.getFilesDir() + getResources().getString(R.string.slash) + name);
        outputStream = new BufferedOutputStream(new FileOutputStream(localFile));
    }

    ftp.retrieveFile(name, outputStream);
    outputStream.close();
}

The only reason I can think of is the files' volume. Is it possible that while downloading the file volume increases? Does anyone had such a problem in the past?

EDIT: So, at least I found the result of copying. Original example file length is 15.1s. Playing the copied file in a music program shows the same length and lasts 15.1s aswell. However using Goldwave I discovered that the copied file is accelerated and ends at 13.8s!

EDIT2: I have also tried zipping all the sounds and unzipping in the app - this is unbeliveable, but only one sound is able to unzip, completely damaged... also, the zip file is not visible via PC.

The default file type was probably ASCII and that caused the problem. The solution is to change it after connecting:

ftp.setFileType(FTP.BINARY_FILE_TYPE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM