Hybrid View

  1. #1
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,704
    Vote Rating
    751
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default Download and encode mp3

    Download and encode mp3


    I'm trying to create an app that can download an mp3 file and then write it to a file.

    Currently I can locate the file and it says it has downloaded the file. It'll even create a file but writing to the file isn't working. I'm not sure how I can encode the file or if the file is downloading correctly.

    Code:
    	function init() {
    		ProgressWin.show();
    		var loader = new air.URLLoader();
    		
    		loader.dataFormat = air.URLLoaderDataFormat.BINARY;
    		
    		configureListeners(loader);
    
    		var request = new air.URLRequest(host+filename);
    		try {
    			loader.load(request);
    		} catch (error) {
    			air.trace("Unable to load requested document.");
    		}
    	}
    
    	function configureListeners(dispatcher) {
    		dispatcher.addEventListener(air.Event.COMPLETE, completeHandler);
    		dispatcher.addEventListener(air.ProgressEvent.PROGRESS, progressHandler);
    	}
    
    	function completeHandler(event) {
    		var loader = air.URLLoader(event.target);
    		Ext.getCmp("progressBar").updateProgress(0, "Writing File...");
    		
    		var file = air.File.desktopDirectory.resolvePath( filename );
    		var stream = new air.FileStream();
    		
    		stream.open( file, air.FileMode.WRITE );
    		stream.writeMultiByte( loader.data, air.File.systemCharset );
    		stream.close();
    	}
    
    	function progressHandler(event) {
    		var tmp = event.bytesLoaded/event.bytesTotal;
    		Ext.getCmp("progressBar").updateProgress(event.bytesLoaded/event.bytesTotal, "Downloading...");
    		tmp = Math.round(tmp*100);
    		Ext.getCmp("progressWin").setTitle(tmp+"% Complete");
    	}
    When I do an air.trace() it says the loader.data is "null" but it is executing the progressHandler() and updating the progressBar.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,704
    Vote Rating
    751
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Ok I found out. If I would have taken my time I would have noted that when using "air.URLLoaderDataFormat.BINARY" that it stores the data in a bytearray so I needed to use writeBytes to write the file. It works and plays the MP3! Final code:

    Code:
    	function init() {
    		ProgressWin.show();
    		var loader = new air.URLLoader();
    		loader.dataFormat = air.URLLoaderDataFormat.BINARY;
    		configureListeners(loader);
    		
    		var request = new air.URLRequest(host+filename);
    		
    		try {
    			loader.load(request);
    		} catch (error) {
    			air.trace("Unable to load requested document.");
    		}
    	}
    
    	function configureListeners(dispatcher) {
    		dispatcher.addEventListener(air.Event.COMPLETE, completeHandler);
    		dispatcher.addEventListener(air.ProgressEvent.PROGRESS, progressHandler);
    	}
    
    	function completeHandler(event) {
    		var loader = air.URLLoader(event.target);
    		Ext.getCmp("progressBar").updateProgress(0, "Writing File...");
    		
    		var file = air.File.desktopDirectory.resolvePath( filename );
    		var stream = new air.FileStream();
    		stream.open( file, air.FileMode.WRITE );
    		stream.writeBytes(loader.data);
    		stream.close();
    	}
    
    	function progressHandler(event) {
    		var tmp = event.bytesLoaded/event.bytesTotal;
    		Ext.getCmp("progressBar").updateProgress(event.bytesLoaded/event.bytesTotal, "Downloading...");
    		tmp = Math.round(tmp*100);
    		Ext.getCmp("progressWin").setTitle(tmp+"% Complete");
    	}
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jul 2013
    Posts
    2
    Vote Rating
    0
    httvhutceoscop is on a distinguished road

      0  

    Default


    Hi, how i can download mp3 file in Sencha Touch 2? Thanks any help.

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar