Commits

Mathias Panzenböck committed 5ca8bdc

BlobBuilder is deprecated

  • Participants
  • Parent commits 2b3491f

Comments (0)

Files changed (2)

javascripts/magnatune.js

 // There is a download attribute for anchor tags, but that's only supported by Chrome so far.
 // http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#attr-hyperlink-download
 var DownloadAttributeSupport = 'download' in document.createElement('a');
+var Blob = window.Blob || window.WebKitBlob || window.MozBlob || window.MSBlob;
+// BlobBuilder is depricated. instead Blobs are now constructable, but only in very recent browsers
+var ConstructibleBlob = true;
+try {
+	new Blob([]);
+}
+catch (e) {
+	ConstructibleBlob = false;
+}
 var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
 var URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
 
 // http://www.w3.org/TR/file-writer-api/#the-filesaver-interface
 window.saveAs = window.saveAs || window.webkitSaveAs || window.mozSaveAs || window.msSaveAs;
 
-if (BlobBuilder && (window.saveAs || navigator.saveBlob)) {
-	// currently only IE 10, but I hope other browsers will also implement the saveBlob method eventually
-	showSave = function (data, name, mimetype) {
+function makeBlob (data, mimetype) {
+	if (ConstructibleBlob) {
+		return new Blob([data],{type:mimetype||"application/octet-stream"});
+	}
+	else {
 		var builder = new BlobBuilder();
 		builder.append(data);
-		var blob = builder.getBlob(mimetype||"application/octet-stream");
+		return builder.getBlob(mimetype||"application/octet-stream");
+	}
+}
+
+if ((ConstructibleBlob || BlobBuilder) && (window.saveAs || navigator.saveBlob)) {
+	// currently only IE 10, but I hope other browsers will also implement the saveAs method eventually
+	showSave = function (data, name, mimetype) {
+		var blob = makeBlob(data, mimetype);
 		if (!name) name = "Download.bin";
 		if (window.saveAs) {
 			window.saveAs(blob, name);
 		}
 	};
 }
-else if (BlobBuilder && URL) {
+else if ((ConstructibleBlob || BlobBuilder) && URL) {
 	// WebKit and Gecko
 	showSave = function (data, name, mimetype) {
-		var builder = new BlobBuilder();
-		builder.append(data);
-		var blob = builder.getBlob(mimetype||"application/octet-stream");
+		var blob = makeBlob(data, mimetype);
 		var url = URL.createObjectURL(blob);
 		if (DownloadAttributeSupport) {
 			// currently only Chrome
 {
   "name": "GreattunePlayer",
   "subdomain": "greattuneplayer",
-  "version": "0.1.0-61",
+  "version": "0.1.0-62",
   "author": "Mathias Panzenböck",
   "description": "This is a proof of concept HTML5 audio player based on the music from Magnatune.com",
   "bin": {