天天看點

ionic3 視訊選擇上傳和錄制上傳

懶得再排版:

選擇上傳

錄制上傳

另附:runtime.ts

import { Injectable } from '@angular/core';
import { Platform } from 'ionic-angular/platform/platform';

@Injectable()
export class Runtime {

	constructor(private platform: Platform) {
	}

	isLAN(url?) {
		url = url || window.location.href;
		return url.indexOf('localhost') >= 0 || url.indexOf('192.168.') >= 0 || url.indexOf('127.0.0.1') >= 0;
	};

	isAndroid() {
		return this.platform.is('android');
	};

	isiOS() {
		return this.platform.is('ios');
	};

	isIPad() {
		return this.platform.is('ipad');
	};

	isIPhone() {
		return this.platform.is('iphone');
	};

	isMobile() {
		return this.platform.is('mobile');
	};

	//判斷是否手機浏覽器
	isMobileBroswer() {
		return this.platform.is('mobileweb');
	};

	isApp() {
		return this.isIonicDebug() || this.isFormalApp();
	};

	isFormalApp() {
		return this.platform.is('cordova');
	}

	isIonicDebug() {
		return !!window['IonicDevServer'];
	};

	isQQ() {
		let match = navigator.userAgent.toLowerCase().match(/\bqq\b/i)[0]
		return match && match[0] == "qq";
	};

	isWeixin() {
		let match = navigator.userAgent.toLowerCase().match(/micromessenger/i);
		return match && match[0] == "micromessenger";
	};

	isPCWeixin() {
		let match = navigator.userAgent.toLowerCase().match(/windowswechat/i)[0];
		return match && match[0] == "windowswechat";
	};
}
           

和Defer.ts

export class Defer {

	public static readonly NoOP = () => { };

	private _resolve;

	private _reject;

	public promise: Promise<any> = new Promise((resolve, reject) => {
		this._resolve = resolve;
		this._reject = reject;
	});

	public static create = () => new Defer();

	public static waitFor(condition: () => boolean, period: number = 100) {
		let defer = new Defer();

		let timer = setInterval(() => {
			if (condition()) {
				defer.resolve();
				clearInterval(timer);
			}
		}, 100);

		return defer.promise;
	}

	resolve(...args: any[]) {
		this._resolve.apply(this._resolve, args);
	}

	reject(...args: any[]) {
		this._reject.apply(this._reject, args);
	}
}

           

繼續閱讀