Iframe video on Android Hybrid App with Phonegap

2019-07-29 17:09发布

问题:

I embedded a youtube video on my index.html file.

<iframe id="video" width="640" height="360" src="//www.youtube.com/embed/xxxxxxxxx?rel=0&amp;controls=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
  • I created the app via cmd with Cordova Phonegap like this:

    cordova create hello com.example.hello HelloWorld
    
  • Replaced my html,css, js files in the app folder.

  • Added android platform:

    cordova platform add android
    
  • Opened Eclipse, imported the app, and run it.

  • I put the .apk on my tablet and everythings works fine, but the video doesn't work.

    I get the error "Web page not avaiable" instead of the video.

How can I fix this?

回答1:

You should probably white list youtube.

http://cordova.apache.org/docs/en/3.6.0/guide_appdev_whitelist_index.md.html

<access origin="http://*.youtube.com" />


回答2:

Solved.

I simply added http: in link on the src attribute.

<iframe id="video" width="640" height="360" src="HTTP://www.youtube.com/embed/xxxxxxxxx?rel=0&amp;controls=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>