Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-13031

Android: Allow HTTPClient.setRequestHeader() to be called after open()

    Details

      Description

      Using HTTP client with Titanium produces different behavior.

      Titanium.UI.setBackgroundColor('#000');
       
      //
      // create base UI tab and root window
      //
      var win1 = Titanium.UI.createWindow({  
      	title:'Window 1',
      	backgroundColor:'#000'
      });
       
       
      var videoID = 'AO2GwKAfEqY';
       
      vdrld = function(a, b) {// We do not get the video-id nor do we get any url; that is, we extract the ID from the image-url.
      	vdldr = Ti.Network.createHTTPClient();
       
      	vdldr.onload = function() {
      		var x, y;
      		Ti.API.error("################# onLoad ##    ###################" + "        "+ this.responseText);
      		x = decodeURIComponent(decodeURIComponent(decodeURIComponent(decodeURIComponent(this.responseText.substring(4, this.responseText.length)))));
      		Ti.API.debug('vdrld: Resulting JSON was: ' + JSON.stringify(x));
      		y = JSON.parse(x).content.video["fmt_stream_map"][0].url;
      		
      		//Ti.API.error(y);
      		alert(y);
      		//Ti.API.error(x);
      		alert(x);
      		
      		if (y === undefined) {
      			Ti.API.error("vdrld: Found no fmt_stream_map in the returned JSON!!!");
      			return;
      		}
      		return b(y);
      	};
      	
      	vdldr.setRequestHeader("Referer", "http://www.youtube.com/watch?v=" + a);
      	vdldr.setRequestHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14");
      	vdldr.open("GET", "http://m.youtube.com/watch?ajax=1&feature=related&layout=mobile&tsp=1&&v=" + a);
      	vdldr.send()
      };
       
      setTimeout(function() {
      	vdrld(videoID, function() {
      		Ti.API.debug('The resulting URL from vdrld was: ' + arguments[0]);
      		var videoPlayerParms = {
      			fullscreen: false,
      			top: 5,
      			width: 320,
      			height: 240,
      			borderColor: '#aaa',
      			autoplay: true,
      			mediaControlStyle: Titanium.Media.VIDEO_CONTROL_EMBEDDED,
      			scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FIT,
      			url: arguments[0],
      		};
      		var videoPlayer = Ti.Media.createVideoPlayer(videoPlayerParms);
      		win1.add(videoPlayer);
      	});
      }, 5000);
       
      win1.open();
      
      

      Above is working in iOS but giving error in android

      Error Message: setRequest Header can only be called before invoking send

      it seems like behavior is not similar in iOS and Android, as i change the order of setRequestHeader method and open method then it works on both but if i try the same code then it does not show error in iOS but in Android it produces the error message mentioned above.

        Attachments

          Activity

            People

            • Assignee:
              sunila Sunila
              Reporter:
              anigam Ashish Nigam
              Reviewer:
              Allen Yeung
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-15867
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Source Code