I am about to develop an application that is to run on Windows 8.1 tablets. An important feature is to be able to click on a button to access the camera to take some pictures. Ideally I would like to create it as a Web application rather than a native application due to a number of reasons (licences, cross-platform, development time: have no experience in native apps, etc.).
I have looked at the options for capturing images from HTML 5 and have found HTML Media Capture which allows me to write:
<input type="file" accept="image/*" capture="camera" />
To get access to the camera. This works great on iPads and on Android tablets, but I can't get it to work on Windows 8 tablets. I have tried using Chrome on the Windows 8 tablet, but still no effect. All it does is that it opens a file dialog in which I can choose a file to upload. What I want to do is to be able to capture a new image. This standard is not supported by IE (an apparently the other browsers cannot access the device's camera either).
I have also stumbled across Media Capture and Streams which seems to be mostly related to showing streams from e.g. the web cam, but probably could be used to capture images and is supported by Chrome and Firefox among other browsers, but still not by Internet Explorer (even IE11). None of the three browsers' implementations seem to work on my Windows 8.1 test machine though. If someone has gotten getUserMedia to work on Windows 8 tablets in any browser I'm interested in hearing about it.
Anyway, my main question is: Is there any way to access the camera on a Windows 8 tablet using HTML5 from a web application? The only working examples I have seen have relied on a prototype implementation for IE using Active X or solutions that use flash.
EDIT: I would very much prefer to keep it in HTML5/javascript as it has to work offline (using HTML5 Application Cache)
I struggled very much for this solution, at the end I find good a solution. But only can use in windows store apps like chrome windows 8 mode (chrome settings -> relaunch chrome in windows 8 mode) then you can use the normal file input tag in html. when you hit "choose file" u see the image below. Then u can choose camera to add take image from camera.
if you can not see camera in the list, u can install app below.
https://www.microsoft.com/en-US/store/apps/Camera-File-Open-Picker/9WZDNCRFJQVN
So I was running into the exactly same issue. My web app is similar, except I have to do some bar code scanning with the tablet's camera.
I'm using the HTML 5 media api as you commented. In order to make it work in chrome in a Windows 8 Surface Pro, I had to do this:
To enable getUserMedia in Chrome type ‘chrome://flags/’ in URL bar and enable “Enable screen capture support in getUserMedia(). Mac, Windows, Linux, Chrome OS” option.
It was working in my laptop but not in the tablet, after making that change and restarting chrome it worked. Good luck.
Here is the code I ended up using to get around this situation... It appears to work in chrome very well however still no support for Internet Explorer which is known not support getUserMedia. Again I wish this wasn't necessary and windows just supported the take picture feature like iOS and android but it works for now.
Credit:
http://davidwalsh.name/browser-camera
// Put event listeners into place
window.addEventListener("DOMContentLoaded", function() {
// Grab elements, create settings, etc.
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
video = document.getElementById("video"),
videoObj = { "video": true },
errBack = function(error) {
console.log("Video capture error: ", error.code);
};
// Put video listeners into place
if(navigator.getUserMedia) { // Standard
navigator.getUserMedia(videoObj, function(stream) {
video.src = stream;
video.play();
}, errBack);
} else if(navigator.webkitGetUserMedia) { // WebKit-prefixed
navigator.webkitGetUserMedia(videoObj, function(stream){
video.src = window.webkitURL.createObjectURL(stream);
video.play();
}, errBack);
}
else if(navigator.mozGetUserMedia) { // Firefox-prefixed
navigator.mozGetUserMedia(videoObj, function(stream){
video.src = window.URL.createObjectURL(stream);
video.play();
}, errBack);
}
document.getElementById("snap").addEventListener("click", function() {
context.drawImage(video, 0, 0, 640, 480);
});
}, false);
getUserMedia interface works in Chrome on my Surface 2, prove:
I've implemented solution described here:
http://www.html5rocks.com/en/tutorials/getusermedia/intro/
Btw, there is a working example on their site as well:
getUserMedia doesn't work in IE
getUserMedia probably works in FF, but I didn't test
access to the camera from [Browse] button doesn't work in any browser on my Surface 2
EDIT: Just realized, my approach doesn't work on Surface any more. Same story for the html5rocks page, the example given doesn't work on Surface. I guess, new Chrome version stopped to support something. BUT I've found the example which works on Surface for Chrome and Firefox, here you are:
http://www.ceng.metu.edu.tr/~e1559848/demos/qrdecode/index.html
Related
I am creating p2p application to share video and screen from Chrome to Mozilla. When I work with Chrome on both sides, it works fine. But when Mozilla is receiving screensharing video, I get a problem.
To start screenshare I do the following in Chrome:
connection.addStream({screen: true, oneway: true}
On the client side I have this callback:
connection.onstream = function (e) {
// handle input stream
}
With Mozilla this callback is not launched, but I see flickering on my main webcam stream: few frames from webcam and few frames from screenshare continiously.
How can I fix this? Is this Mozilla bug?
it you're adding more than one stream to a single peerconnection, you may be hitting the fact that Chrome and Firefox support different dialects of SDP.
Unless you do translation of the SDP, you'll have to use different peerconnections until the chrome bug is fixed.
My solution was migrating to SimpleRTC (http://simplewebrtc.com). This is same sort of library, but it is updated regularly to reflect browsers/API changes. The challange was signalling layer, because it uses special (opensource) library on top of socketio to handle chat rooms. But now screensharing works correctly.
I'm creating a Audio Player with HTML5, using the MediaSource Object.
My code is similar to MediaSource API Demo
But when executing the line
var ms = new MediaSource();
And exception is throwed on Firefox and Internet Explorer
ReferenceError: MediaSource is not defined
In Firefox Support says that this feature is only enabled to Youtube and Netflix.
There is a way to handle this restriction?
In Chrome, I have not problem!
At time of writing, IE11 only has support when run on Windows 8.1 or above.
Firefox will only enable MSE when about:config param media.mediasource.enabled = true (this restriction will be removed eventually, once the FF implementation is globally stable). There is no way around this, so unless you are YouTube or Netflix, consider Firefox MSE as coming soon.
Firefox has been lagging behind quite badly when it comes to MSE support in their browser. Firefox Nightly build however now seems to be pretty close to working properly. It still has to go through nightly build and beta phase before it's released to the public, so expect a few months.
I just recently downloaded and installed the Samsung Smart-TV SDK 4 (without the IDE, just the emulator). I'm doing this because I want to test the Web browser only, nothing else.
However, when I start up the emulator (2012 version), I can't find any apps when I get to smarthub. I've created a Samsung account but I see no default apps that would usually appear on the TV, not even the Internet browser.
Is there something I'm missing?! I just want to test the Internet Browser.
Cheers.
The emulator is provided for testing your own apps, not to run the apps that people who buy TVs/BRPs/etc get with their device.
Only apps you write and place in the apps/ directory will appear.
That said, you can write an app that does nothing except:
location.href = "http://example.com/";
if i write an app with just location.href = "http://example.com/ is working (i have sdk 5.0) but the browser i get on the TV is not the same browser i get on the tv if i just lunch the integrated web browser app.
The big difference i see is that my app has a browser without the top bar with navigation controls and also there is no mouse pointer and i need to connect an external usb mouse to the tv
how should i do to implement this ?
Using the standard HTML5 geolocation code, I am able to access the geolocation on desktop browsers (Chrome, Firefox), but not on my Samsung Galaxy S3 (default browser, Chrome). In the default browser, nothing at all happens. In Chrome, the yellow permissions form pops up at the bottom but then pops down too quickly to press anything. I have checked that Location is enabled in Settings. I am considering looking for a PHP solution as a backup for cases when JavaScript/HTML5 solution breaks down like this, but would prefer that the JavaScript solution be more robust.
Has anyone come across this and fixed it? Any ideas?
For reference, the "standard" HTML5 geolocation code I'm referring to is this (sample code from: Basic Geolocation in HTML5):
<script type="text/javascript">
if( navigator.geolocation )
{
// Call getCurrentPosition with success and failure callbacks
navigator.geolocation.getCurrentPosition( success, fail );
}
else
{
alert("Sorry, your browser does not support geolocation services.");
}
function success(position)
{
// GeoPosition Object
alert("Your coordinates are " + position.latitude + ", " + position.longitude);
}
function fail()
{
// Could not obtain location
}
</script>
Odd. I did 3 things and now it works in both phone browsers (default and chrome)
I put the main code in a function that is called in <body onload="">
I restarted my phone
I turned off power saving mode
I suspect the restart did the most for it, since I was seeing the permission pop up flash across the screen in chrome.
Does anybody know how to use HTML5 to achieve uploads by drag-drop files form desktop?
I have found the following references:
Selecting files using drag and drop (2017-08) on developer.mozilla.org
Drag and drop file uploading using JavaScript the article states that the api was changed and links to The File Api has changed (2010-09)
html5-drag-and-drop-multiple-file-upload (2017-11 returns 404) on http://www.appelsiini.net/ (is still live)
but is there a solution that can run on all platforms: Firefox, Chrome and Safari?
Many thanks!
Sorry, at the moment there is no cross browser solution available.
Current Browser Implementation Issues
FF, Safari, Chrome, IE (Cross-Browser Issues)
No recursive folder uploading -- as a matter of fact, no folder uploading at all. While this isn't a show stopper, it does seem kind of silly to allow a user to select a folder in the file upload input box if the browser won't send all the files inside that folder too.
Firefox 3.6.*
This browser supports file drag and drop, however the implementation is quite possibly the worst ever conceived. In order to upload a file that the user dropped, we have to read the entire file into memory and then send it over Ajax to our servers. This works fine for drops of around 10MB. If you try that same operation with a 400MB file, forget it!
Firefox 4.* (Beta)
The Mozilla developers are quick ones -- they realized the problem with their previous implementation and have created a whole new way to implement drag and drop uploading. The FormData object is a new JavaScript object that allows a web developer to insert file uploads directly into an Ajax request without reading the files into memory first. I was really excited about this and promptly downloaded Firefox 4 which is in its 2nd beta. After playing around with it for less than 5 minutes, I strongly discourage you from trying it yet. My system became incredibly unstable and slow and development was a major pain due to lack of support for Firebug.
Chrome (latest)
This browser is by far the best in its implementation! Simple and straightforward, my only complaint here is that you can't upload a folder and its contents via drag and drop.
Safari 4.* & 5.*
Since Safari is built on top of WebKit just like Google Chrome, I expected it to work just as well. Wow, was I mistaken! I tried this in both Safari 4 and Safari 5. While dragging and dropping multiple files into the window works, Safari sends the first file multiple times, instead of sending all the files. Talk about a MAJOR bug. To make it even more interesting, if the user clicks on the drop location, they can select multiple files to upload using the standard file selection dialog -- and that works as expected! I can't wait for Safari to fix this issue.
Internet Explorer
To be honest, I haven't even bothered trying to do drag and drop uploads in Internet Explorer yet. Trying to support IE is a pain due to lack of good development tools and a non-conforming JavaScript engine. Since I haven't been able to get all the preferred browsers to play nice, I can't imagine Internet Explorer will be even close.
source
I would defiantly look into running Plupload. It allows great browser capability and supports multiple file drag and drop in HTML5 browsers that support FileReader.
So lets say for example you dont have html 5 it will deprecate down to flash / gears / silverlight depending on what that individual has installed.
Here's the compatibility chart:
http://www.plupload.com/index.php
It has an option called droparea: "somediv" that allows you to drag files into it and automatically cue up a file upload.
Let me know if you need any help setting it up.
Here is a simple example. If you drag an image over the red div it appends the image to the body. I've confirmed it works in IE11, Chrome 38, and Firefox 32. See this Html5Rocks article for a more detailed explanation.
<div id="dropZone" style="width: 100px; height: 100px; background-color: red"></div>
<script>
var dropZone = document.getElementById('dropZone');
// Optional. Show the copy icon when dragging over. Seems to only work for chrome.
dropZone.addEventListener('dragover', function(e) {
e.stopPropagation();
e.preventDefault();
e.dataTransfer.dropEffect = 'copy';
});
// Get file data on drop
dropZone.addEventListener('drop', function(e) {
e.stopPropagation();
e.preventDefault();
var files = e.dataTransfer.files; // Array of all files
for (var i=0, file; file=files[i]; i++) {
if (file.type.match(/image.*/)) {
var reader = new FileReader();
reader.onload = function(e2) {
var img = document.createElement('img');
img.src= e2.target.result;
document.body.appendChild(img);
}
reader.readAsDataURL(file);
} } });
</script>