HTML Viewer

I am loading a youtube video into the html viewer and have 2 queries.

  • How can you test that you have an internet connection and it is loading?

  • How can you just get the video and not the comments and suggested videos underneath?

Hi Martin,
For the first one check out my Reachability class in iOSKit. I’m not sure about the second question maybe there is an API?

Use the YouTube embed code in an HTMLViewer.

This is the embed code for a Xojo webinar on YouTube. I’ve added tags and put it into a constant (kYouTubeEmbed):

[code]

[/code]

This code saves the constant to a local file (in Documents on the device) and then loads it into the HTMLViewer, which plays the video:

[code] // Save iframe content as a file
Dim outFile As FolderItem = SpecialFolder.Documents.Child(“YouTube.html”)
Dim output As TextOutputStream
output = TextOutputStream.Create(outFile, TextEncoding.UTF8)
output.Write(kYouTubeEmbed)
output.Close

// Load the file into the HTMLViewer to display the embedded YouTube video
HTMLViewer1.LoadURL(outFile.URLPath)[/code]

[quote=281186:@Jason King]Hi Martin,
For the first one check out my Reachability class in iOSKit. I’m not sure about the second question maybe there is an API?[/quote]
Hi Jason, the reachability in ioskit gives back false positives if i have wifi connection, but not internet connection.

I’m not sure I understand? If you have wifi you should have internet connection. The class uses Apple’s API and it returns whether or not it is able to reach google.com through each of the methods. Is it possible the problem is the site you are trying to access is down? If there is a bug there then maybe you need to file a bug report with Apple about it, although I have never seen this problem.

I think he means connection to the Local Area WiFi network but not connection to the Internet.

Hmm, it still shouldn’t say he is reachable if it can’t get to google. Maybe the network has access to google and nothing else without authentication or similar?

Hi Paul, Just wondering why you have to write the path out to a text file?

Hi Jason, what specific bits from the kit do I need?

Hi Jason, i use the wifi-hotspot option on my android mobile phone to create wifi signals. The phone does not have access to the internet, but the ios app says its “reachable via wifi”. So i can’t use it to detect if i have access to the internet or not.

I tested the lib this way, cuz i did not want to plug out the ethernet cables from our company’s router.

internet -› router -› wifi - › ipad = reachable via wifi
android phone without internet acces + wifi hotspot option enabled - › ipad = reachable via wifi
Just tested it again 2 times with different phones.

You have to write the HTML to a file in order to load it as a URL with the iOSHTMLViewer.LoadURL method.

Hi Paul, I have implemented the suggestion above exactly but just get a blank screen. (the page loads HTMLViewer1.LoadURL(https://www.youtube.com/embed/vCGNB94y0DU)
What is the most likely error?

[quote=281553:@Martin Fitzgibbons]Hi Paul, I have implemented the suggestion above exactly but just get a blank screen. (the page loads HTMLViewer1.LoadURL(https://www.youtube.com/embed/vCGNB94y0DU)
What is the most likely error?[/quote]

Have you checked the same URL with mobile Safari ? All browsers use the same engine. It is possible that youtube using its own player, that does not work on iOS.

Using a data URI, it is possible to load an HTML Viewer with dynamic content, without having to write the content out to a file.

I put together a very basic iOS project that demonstrates this approach: http://timdietrich.me/fmblog/assets/DataURIExample.xojo_binary_project.zip

This example simply loads the Youtube video that Paul provided above.

Note that you must URL encode the content. The “urlencode” method that I used in this example is, admittedly, pretty basic as well - but it works.

Anyway, I hope this helps.

[quote=281553:@Martin Fitzgibbons]Hi Paul, I have implemented the suggestion above exactly but just get a blank screen. (the page loads HTMLViewer1.LoadURL(https://www.youtube.com/embed/vCGNB94y0DU )
What is the most likely error?[/quote]
Not sure. Works fine here for me in the iOS Simulator.

You can download my project here: YouTubeViewer

[quote=281349:@Roland Maszlag]Hi Jason, i use the wifi-hotspot option on my android mobile phone to create wifi signals. The phone does not have access to the internet, but the ios app says its “reachable via wifi”. So i can’t use it to detect if i have access to the internet or not.

I tested the lib this way, cuz i did not want to plug out the ethernet cables from our company’s router.

internet -› router -› wifi - › ipad = reachable via wifi
android phone without internet acces + wifi hotspot option enabled - › ipad = reachable via wifi
Just tested it again 2 times with different phones.[/quote]
Seems like a bug with Apple then. I’m not sure I can do anything unfortunately.

I’ve been thinking about the need to test for connectivity, and here’s what I’ve come up with.

Here’s a link to a Xojo project file that demonstrates the technique:
http://timdietrich.me/fmblog/assets/ConnectivityTest.xojo_binary_project.zip

When the app opens, the initial view creates an instance of a class that’s based on an HTTPSocket. The constructor for the class takes an iOSLabel and an iosView as parameters, and stores them as properties so that they can be referred to later. The constructor then sends an HTTP HEAD request to Google. This is the actual connectivity test, and because it’s only a HEAD request, only headers are returned. The test happens quickly, regardless of whether there is connectivity or not.

If the HEAD request fails, then the “Error” event handler fires, and the label is updated so that the user knows that they don’t have connectivity. If the request is successful, then the “PageReceived” event handler fires, and the app’s “CurrentScreen” is replaced with the view that was passed as a param.

I’ve tested this technique, and it seems to work pretty well. However, the connectivity test only happens when the app is originally opened. I’m sure there’s a way to perform the test if the app is resumed, but I haven’t had a chance to experiment with that.

Nice one Tim