<!DOCTYPE html>
<html>
<body>
<button onclick="playVid()" type="button">Play</button>
<button onclick="pauseVid()" type="button">Pause</button>
<button onclick="seekVid()" type="button">Seek</button>
<button onclick="ccVid()" type="button">CC</button><br>
<video id="myVideo" width="600" height="400" autoplay="autoplay" controls='false'>
<source src="./big.mp4" type="video/mp4">
<track label="pt" kind="subtitles" srclang="pt" src="./small.vtt" default />
Your browser does not support the video tag.
</video>
<script>
var vid = document.getElementById("myVideo");
var aaaa = 'showing';
function myFunction() {
document.getElementById("myVideo").controls = true;
}
function playVid() {
vid.play();
}
function pauseVid() {
vid.pause();
}
function seekVid() {
var cTime = vid.currentTime;
vid.currentTime += 3;
}
function ccVid() {
if (aaaa==='showing')
aaaa = 'hidden';
else
aaaa = 'showing';
for (var i = 0; i < vid.textTracks.length; i++)
vid.textTracks[i].mode = aaaa;
}
</script>
</body>
</html>
Friday, March 23, 2018
Monday, March 12, 2018
Android之webview
1. webview的基本代码
https://developer.android.com/guide/webapps/webview.htmlwebview.xml:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
MainActivity.java:
public class MainActivity extends Activity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.setJavaScriptEnabled(true);
webView.loadUrl("http://www.vtasters.com/unittest");
//webView.loadUrl("file:///android_asset/abc.html");//in app/assets/abc.html
AndroidManifest.xml:
<manifest ... >
<uses-permission android:name="android.permission.INTERNET" />
...
</manifest>
2. JS和webview交互
http://mthli.github.io/Android-WebView-JavaScript需要准备一个网站如vtasters,webview可以通过loadUrl来执行对应功能。
public class MyWebView extends WebView {
public MyWebView(Context context) {
...
getSettings().setJavaScriptEnabled(true);
addJavascriptInterface(this, "MyName");
...
}
@JavascriptInterface
public void example() {
...
}
}
Sunday, February 25, 2018
Protobuf协议
http://blog.csdn.net/antgan/article/details/52103966
解码:
http://yura415.github.io/js-protobuf-encode-decode/
解码:
http://yura415.github.io/js-protobuf-encode-decode/
Friday, December 15, 2017
NodeJS模拟HTTP server
遇到问题是CORS,需要模拟一些allow-header和allow-origin
https://www.npmjs.com/package/node-mock-server
https://github.com/node-nock/nock
https://www.npmjs.com/package/node-mock-server
https://github.com/node-nock/nock
Friday, December 1, 2017
Friday, November 17, 2017
CORS简介
CORS是一个W3C标准,全称是"跨域资源共享"(Cross-origin resource sharing)。
CORS只针对浏览器,因为浏览器安全性的考虑,会拒绝向不允许访问的资源网站发送请求。过程是
1. 某网站的Ajax代码尝试去访问其他网站的资源(html,图片),
2. 这时候浏览器会自动加入先发一个CORS请求
3. 服务器whitelist了这个请求,返回response包含允许allow-origin=该网站的header。如果服务器不允许,浏览器收到response不含origin信息就会停止发送真正的请求。
4. 其后,每一个请求都会自动加入allow-origin的header。
其实,这只是浏览器的限制,如果用fiddler或者postman,甚至HTTPclient的lib是不会有这些限制的。
HTTP方法包括GET, POST, PUT, DELETE, OPTIONS
CORS的Jersey(Restful web service in Java)实现
https://gist.github.com/yunspace/36b0546245c5348a34ed
ref:
http://www.ruanyifeng.com/blog/2016/04/cors.html
CORS只针对浏览器,因为浏览器安全性的考虑,会拒绝向不允许访问的资源网站发送请求。过程是
1. 某网站的Ajax代码尝试去访问其他网站的资源(html,图片),
2. 这时候浏览器会自动加入先发一个CORS请求
3. 服务器whitelist了这个请求,返回response包含允许allow-origin=该网站的header。如果服务器不允许,浏览器收到response不含origin信息就会停止发送真正的请求。
4. 其后,每一个请求都会自动加入allow-origin的header。
其实,这只是浏览器的限制,如果用fiddler或者postman,甚至HTTPclient的lib是不会有这些限制的。
HTTP方法包括GET, POST, PUT, DELETE, OPTIONS
CORS的Jersey(Restful web service in Java)实现
https://gist.github.com/yunspace/36b0546245c5348a34ed
ref:
http://www.ruanyifeng.com/blog/2016/04/cors.html
Sunday, July 16, 2017
MySQL难点
select ... for update将会锁住任何其他connection的select for update, update, insert。当然还要放入到transaction中。
CREATE DEFINER=`qfu`@`%` PROCEDURE `updateIndex`(IN batchNum INT)
BEGIN
DROP TEMPORARY TABLE IF EXISTS temp;
create temporary table temp(id int);
START TRANSACTION;
insert into temp
select id from Dow_Jones_Index2 where isUpdated=0 limit batchNum for update;
update Dow_Jones_Index2 set isUpdated=1 where id in (select id from temp);
commit;
select * from Dow_Jones_Index2 where id in (select id from temp);
DROP TEMPORARY TABLE IF EXISTS temp;
END
临时表生命期是session内,如果数据库连接断了,临时表也会消失。相当于mssql中的#temp
---
explain select * from Student where id=5;
可以解释是否用了index。
Using where: 没用到index
Using index: index含有所有信息不需要再查表。The difference is that "Using index" doesn't need a lookup from the index to the table, while "Using index condition" sometimes has to.
Using index condition: 需要再查表
clear cache for performance tuning (workbench)
RESET QUERY CACHE;
ref:
select for update
Subscribe to:
Posts (Atom)