File exists or not?

You must Login before you can answer or comment on any questions.

Hi there,

    i have changed the function like below because app was waiting to much to open everytime. With this code: 
  1. i am checking the file if exists or not, if doesn't exists i am downloading it to the Application Directory and play from there, so i think it is more faster.

  2. i am using this module from MarketPlace;

    https://marketplace.appcelerator.com/apps/907?351828443#overview

  3. i am making something wrong again i think, while i am chechkin file exists or not , if file doesn't exists i am downloading but after that the sound doesn't start to play?

  4. how can i clean the downloaded files? i am cleaning the project files but they are not cleaning :(

  5. i am really curios about something, can compare the size ot the files? if the remote file is bigger then the local file, i must to download it again

  6. How can i find my ApplicationDataDirectory from my computer? i am using lion and i can't find my user/library/ApplicationSupport Directory?

Thanks for reading

function loopMessageSound() {
        messageSound = Ti.Media.createSound({ preload : true});
 
        var _callBack_DownloadOneFileFinished = function(download_result) {
        Ti.API.info("Finished Downloading:" + download_result.path);
        };
        var file_exists = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,songs[index].mp3);
        Ti.API.info("File Exists:"+file_exists.exists());
        if (file_exists.exists() === false) {
        Ti.API.info("File Doesn't Exists and start Download");
        utility.downloadOneFile("http://www.xxx.com"+songs[index].mp3, Titanium.Filesystem.applicationDataDirectory + songs[index].mp3, messageSound.play());
 
        }else{
        Ti.API.info("File Exists and Don't DOWNLOAD'.")
        }
 
 
        messageSound.url = Titanium.Filesystem.applicationDataDirectory + songs[index].mp3;
 
        messageSound.desc = index+1+". "+songs[index].baslik;
 
        playing.text = messageSound.desc;
        playing.opacity = 0;
 
        playing.animate({ 
        curve: Ti.UI.iOS.ANIMATION_CURVE_EASE_IN_OUT, 
        opacity: 1, 
        duration: 1500
        }); 
                messageSound.addEventListener('complete', function(e) {
            index ++;   
            if (index < songs.length){
 
                loopMessageSound();
 
              } else {
                Ti.API.info("Song Loop Complete");
                index = 0;
                loopMessageSound();
              }
        });
        messageSound.play();
 
 
 
    }

2 Answers

Accepted Answer

Hello, Instead of using

if(file_exists.exists() === false)
simply use
if(!file_exists.exists())

If you need to delete simulator memory then click on close button on simulator , so that your app goes in background , now delete application on simulator by long click on app icon and then selecting delete from alert dialog., this will completely remove application memory from your system . You need to download some software than you can see user/library/ApplicationSupport Directory folder , may be its hidden by default on your mac.

— answered 10 months ago by Moiz Chhatriwala
answer permalink
2 Comments
  • Thanks for your reply, i did like you said, but the player doesn't continue after downloading the mp3?it gives error like this

    Error Domain=NSOSStatusErrorDomain Code=-43

    — commented 10 months ago by Graham Jeffrey

  • i have two buttons play_btn and pause_btn to control the player, i have modified my code like this

    utility.downloadOneFile("http://www.xxx.com"+songs[index].mp3, Titanium.Filesystem.applicationDataDirectory + songs[index].mp3, _callBack_DownloadOneFileFinished);
    instead of
    utility.downloadOneFile("http://www.xxx.com"+songs[index].mp3, Titanium.Filesystem.applicationDataDirectory + songs[index].mp3, messageSound.play());
    and i have make a new function :
    function resetPlayer(){
        pause_btn.fireEvent("click");
        play_btn.fireEvent("click");
    }
    and modified the _callBack_DownloadOneFileFinished function to
    var _callBack_DownloadOneFileFinished = function(download_result) {
            Ti.API.info("Finished Downloading:" + download_result.path);
            resetPlayer();     
            };
    it works now but still giving the error
    Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)". error loading sound url:
    is this a bad thing?

    When i run the app second time it doesn't give any errors? but i think i need to compare the file sizes or duration for a clean download?

    — commented 10 months ago by Graham Jeffrey

you can check the timestamp on the file and only download if there is a newer file? Are you writting the code on the server?

Your Answer

Think you can help? Login to answer this question!