Incorporating Vimeo using JavaScript API on iOS devices

I have been attempting to use Vimeo's JavaScript API () in order to control an embedded video through my application, but I am encountering difficulties even with their provided example (http://jsfiddle.net/bdougherty/HfwWY/light/)

After downloading the jQuery and Froogaloop JavaScript files used in the fiddle, I copied them into Xcode and ensured they were placed under Bundle Resources, as suggested by some sources.

In my ViewController, I have included:

NSString *path = [[NSBundle mainBundle] pathForResource:@"vimeo" ofType:@"html"];
NSString *html = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

[_webby loadHTMLString:html baseURL:[[NSBundle mainBundle] bundleURL]];

The contents of my vimeo.html file are as follows:

<html>
<body>
<iframe id="player1" src="http://player.vimeo.com/video/27855315?api=1&player_id=player1" width="400" height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>

<p>Video status: <span class="status">...</span></p>
<p><button>Play</button> <button>Pause</button></p>

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="froogaloop2.min.js"></script>
<script type="text/javascript" src="player.js"></script>

</body>

Where jquery.min.js can be found at https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js and froogaloop2.min.js at

My player.js is similar to the fiddle example with an ondomready function defined:

$(document).ready(function () {
var iframe = $('#player1')[0],
    player = $f(iframe),
    status = $('.status');

// When the player is ready, add listeners for pause, finish, and playProgress
player.addEvent('ready', function() {
    status.text('ready');
    
    player.addEvent('pause', onPause);
    player.addEvent('finish', onFinish);
    player.addEvent('playProgress', onPlayProgress);
});

// Call the API when a button is pressed
$('button').bind('click', function() {
    player.api($(this).text().toLowerCase());
});

function onPause(id) {
    status.text('paused');
}

function onFinish(id) {
    status.text('finished');
}

function onPlayProgress(data, id) {
    status.text(data.seconds + 's played');
}
 });

The documentation mentions that: "You’ll need to be running on a web server instead of opening the file directly in your browser. Flash and JS security restrictions will prevent the API from working when run locally."

I am unsure how to avoid opening the JS file directly in my browser, although someone suggested changing this line in my ViewController:

[_webby loadHTMLString:html baseURL:[[NSBundle mainBundle] bundleURL]];

I attempted modifying it to something like:

[_webby loadHTMLString:html baseURL:[NSURL URLWithString:@"http://player.vimeo.com/"]];

Unfortunately, this approach did not work for me either.

Answer №1

Dealing with a similar issue, I found a solution that worked for me:

  1. To ensure functionality, specify http://player.vimeo.com as your base URL.

  2. I had trouble referencing local js files, so I resorted to using the remote source instead:

    <script src="http://f.vimeocdn.com/js/froogaloop2.min.js"></script>
    
  3. In my case, I skipped jquery and simplified my code to look like this:

        var iframe = document.getElementById('player1');
        var player = $f(iframe);
    
        player.addEvent('ready', function()
        {
            sendNotification('onReady', '');
    
            player.addEvent('pause', onPause);
            player.addEvent('finish', onFinish);
            player.addEvent('playProgress', onPlayProgress);
        });
    
        function onPause(id)
        {
            sendNotification('onStateChange', 'paused');
        }
    
        function onFinish(id)
        {
            sendNotification('onStateChange', 'finished');
        }
    
        function onPlayProgress(data, id)
        {
            sendNotification('onPlayTime', data.seconds);
        }
    
        function sendNotification(action, data)
        {
            var message = {};
    
            message['action'] = action;
            message['data'] = data;
    
            window.webkit.messageHandlers.observe.postMessage(message);
        }
    

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring ways to extract an element from a newly opened window and set a value using JavaScript

I have been successfully using web_browser.document.getElementById() for the login screen, but I am encountering an issue when trying to use it after logging in and opening a new window. Can someone please assist me with this problem? Below is the code t ...

SQLite3 does not allow for whitespace within text when working with Objective-C

I am working on developing an iOS app with a sqlite3 database following this tutorial. Instead of the typical name, lastname, and age fields, I am using name and the current date. To display the current date, I am utilizing NSDate and showcasing it in a U ...

Is there a simple solution to show script 1 to visitors from the US and Canada, while displaying script 2 to visitors from other countries?

I'm looking for a simple script that can show one script to visitors from the US and Canada, and another script to visitors from other countries. It doesn't have to be perfect, but using a service like seems too complex for me. Is there a stra ...

`Generate JSON list`

How can I properly encode an array in PHP as JSON, ensuring it includes two variables? $var = 33; $last = 44; Here are the database results: foreach($query->result() as $r) { $data[]= $r; // Fills the array with results } I am attempting to cre ...

Issues loading resource: bundle.js generates successfully in NodeJS and React app, however, error 404 occurs

I am currently working on a simple practice project where I have some initial content (a '...' string) in the JS environment. My goal is to load React after the JS environment loads and replace the content with a 'hello react' string wi ...

Creating a collection by gathering data from interactive fields with the help of AngularJS

I have a project to create an attendance system for employees. The system requires me to track the attendance status of each employee by generating a dynamic form with text input fields and checkboxes using angularjs ng-repeat inside a table. This form wil ...

Access an HTML page programmatically using JavaScript

Make sure to have a confirmation window pop up before submitting the form, and after confirming submission (by clicking OK), redirect to a confirmation page. Here's an example code snippet: <button type="submit" value="Save" id="Save" onclick="cl ...

Submitting a form with backbone framework

Utilizing Backbone to handle form submissions, which are located on the HTML homepage. The .save() method of the Backbone model is used to store data in the database upon form submission. In order to prevent default submission behavior and capture the valu ...

Ensure that text is aligned alongside an image only when both elements are enclosed within <p> tags

When using an API to pull markdown content from Contentful and converting it to HTML with ReactMarkdown, a common issue arises. The resulting HTML structure often places the text content in separate paragraphs such as: <p>Some text content</p> ...

Issue with accessing Vue.js parameter in route

Trying to work with both VueJS and Laravel, I am currently facing an issue where I cannot retrieve a parameter value. Can anyone provide guidance on how to solve this problem? This is my VueJS code: getTestData:function () { let config = { par ...

What is the best way to set a newly selected HTML option as the first choice?

I'm facing a simple problem in JavaScript that I can't seem to crack. Admittedly, I am new to working with JavaScript. My issue lies with sorting a dropdown list in alphabetical order while also keeping the selected value at the top. Whenever a ...

Issue with jQuery .ajax() not triggering success callback function when using JSONP

My Facebook iframe application is attempting to make a cross-domain request to my server for JSONP data. The client-side code I am using is as follows: jQuery.ajax({ url: '***', type: 'post', ...

What is the method for adding 24 hours to a 12-hour timestamp while preserving the AM and PM designation?

I have created the following code to display real-time, but I am struggling with adding a timestamp that switches from 24-hour format to 12-hour format with AM and PM. setInterval(function() { var date = new Date(); var hours = date.getHours(); va ...

What is the best way to keep an HTML table header fixed within a div while scrolling?

My HTML table now has the scrolling function. Below, you can find the code snippet for the HTML table setup. <div id="flagging" > <table> <thead> <th> Header 1 </th> <th> Header 2 </th> ...

What is the best way to set up a simple example using a Node Stream.Readable?

I am currently exploring the concept of streams and encountering some difficulties in making it work properly. For this scenario, my goal is to send a static object to the stream and then pipe it to the server's response. This code snippet shows my ...

Incorporate unique color variables from the tailwind.config.js file

I am working on a project using nextjs and typescript, with tailwind for styling. In my tailwind.config.js file, I have defined some colors and a keyframe object. My issue is how to access these colors to use as background values in the keyframe. Here is ...

After the build process, image URLs in Vue 3 + Vite are returning as undefined

Encountered an issue where the URL generated dynamically from props for image import in my Vue 3 component became undefined post-build Check out the script used to generate the URL and the tag in the Vue Component below const imagePath = computed(() => ...

The 'Component' you are trying to use cannot be rendered as a JSX component in Next.js

Take a look at the code in _app.tsx: function MyApp({ Component, pageProps }: AppProps) { return <Component {...pageProps} /> } An error is popping up during the project build process: Type error: 'Component' cannot be used as a JSX comp ...

Exclusive to IOS 11: Turning off the navigation bar label at the top

An issue has been identified where the main label is offset slightly from the top in IOS 11, as opposed to staying aligned with the top. Interestingly, this problem seems to exclusively affect IOS 11, while everything appears fine on other versions of the ...

What is the best way to handle errors generated by my jsdom.jqueryify callback function?

When running this code in node.js, the output is a stack trace of an error that occurs on line 9. Surprisingly, the error on line 7 seems to be 'absorbed' by Node. Even when wrapped in a try/catch statement, the detailed stack trace output is not ...