Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Android ( Emulator too ) and XMLHttpRequest
QtWS25 Last Chance

Android ( Emulator too ) and XMLHttpRequest

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxvanceffer
    wrote on last edited by
    #1

    I have problem to get response from youtube in android.

    From main.qml file making request like this :

    @onTrailerUrlChanged: {
    console.log('loading youtube link');
    var doc = new XMLHttpRequest();
    doc.onreadystatechange = function() {
    if (doc.readyState === XMLHttpRequest.DONE)
    {
    console.log('Youtube link loaded: '+doc.responseText)
    var jsresp = JSON.parse(doc.responseText);
    var entries = jsresp.feed.entry;
    var len = entries.length;
    if (len) {
    var entry = entries[0];
    var thumbnail_url = entry.media$group.media$thumbnail[0].url;
    var video_3gp_url = entry.media$group.media$content[1].url;
    console.log('Thumbnail link '+thumbnail_url);
    console.log('Video url '+video_3gp_url);
    if (thumbnail_url)
    thumbnail_image.source = thumbnail_url;
    if (video_3gp_url)
    trailerRtpsLink = video_3gp_url;
    }
    }
    }

        var video_id = trailerUrl.replace('http://www.youtube.com/watch?v=','');
        console.log('link to parse youtube '+'http://gdata.youtube.com/feeds/api/videos?q='+video_id+'&alt=json&fields=entry/id,entry/media:group/media:thumbnail,entry/media:group/media:content')
        doc.open("GET",'https://gdata.youtube.com/feeds/api/videos?q='+video_id+'&alt=json&fields=entry/id,entry/media:group/media:thumbnail,entry/media:group/media:content');
        doc.send();
    }@
    

    And doc.responseText is empty. But on desktop everthing is working preoprly. I have read that making network request from main thread in android is not supported. Then if qml running in main thread how make request from qml and put in other thread. Is this possible ?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      you should also check if an error has occured once your request has finished, maybe this gives already an clue whats going wrong.
      @
      doc.onreadystatechange = function() {
      if (doc.readyState === XMLHttpRequest.DONE)
      {
      if( doc.status != 200 )
      {
      console.log('ERROR: '+doc.status);
      }
      console.log('Youtube link loaded: '+doc.responseText)
      var jsresp = JSON.parse(doc.responseText);
      var entries = jsresp.feed.entry;
      var len = entries.length;
      if (len) {
      var entry = entries[0];
      var thumbnail_url = entry.media$group.media$thumbnail[0].url;
      var video_3gp_url = entry.media$group.media$content[1].url;
      console.log('Thumbnail link '+thumbnail_url);
      console.log('Video url '+video_3gp_url);
      if (thumbnail_url)
      thumbnail_image.source = thumbnail_url;
      if (video_3gp_url)
      trailerRtpsLink = video_3gp_url;
      }
      }
      }
      @

      Maybe you forgot to add the permissions to your android app to access the internet?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved