1:下载ShareREC资源文件导入工程
2:配置文件
清单文件配置
<activity
android:name="com.mob.tools.MobUIShell"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:windowSoftInputMode="stateHidden|adjustResize" />
初始化:key和server在Sharesdk中找到并且配置好
final SystemRecorder recorder = new SystemRecorder(MainActivity.this, "key", "server");
// 设置视频的最大尺寸
recorder.setMaxFrameSize(Recorder.LevelMaxFrameSize.LEVEL_1280_720);
// 设置视频的质量(高、中、低)
recorder.setVideoQuality(Recorder.LevelVideoQuality.LEVEL_HIGH);
// 设置视频的最短时长
recorder.setMinDuration(10 * 1000);
// 设置视频的输出路径
recorder.setCacheFolder("/sdcard/ShareREC/cvr");
recorder.isAvailable();
找到控件 在相应的控件下执行对应的方法:
开始:
停止:
展示:
直接贴代码
public class MainActivity extends Activity implements OnClickListener, OnRecorderStateListener {
private ViewRecorder recorder;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 初始化UI (init UI)
setContentView(R.layout.main_activity);
findViewById(R.id.btnStart).setOnClickListener(this);
findViewById(R.id.btnStop).setOnClickListener(this);
findViewById(R.id.btnProfile).setOnClickListener(this);
// 初始化ShareRec (init ShareRec)
View view = findViewById(R.id.evCan);
String appkey = "1e845b8c97a73";
String appsecret = "001a5c9908a814bfaf7568bfaca060a7";
recorder = new ViewRecorder(view, appkey, appsecret);
// 设置视频的最大尺寸
recorder.setMaxFrameSize(Recorder.LevelMaxFrameSize.LEVEL_1280_720);
// 设置视频的质量(高、中、低)
recorder.setVideoQuality(Recorder.LevelVideoQuality.LEVEL_HIGH);
// 设置视频的最短时长
recorder.setMinDuration(10 * 1000);
// 设置视频的输出路径
recorder.setCacheFolder("/sdcard/ShareREC/cvr");
recorder.isAvailable();
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnStart: startRecorder(); break;
case R.id.btnStop: stopRecorder(); break;
case R.id.btnProfile: showProfile(); break;
}
}
protected void onPause() {
// 暂停录像 (pause ShareRec)
recorder.pauseRecorder();
super.onPause();
}
protected void onResume() {
super.onResume();
// 恢复录像 (resume ShareRec)
recorder.resumeRecorder();
}
protected void onDestroy() {
super.onDestroy();
System.exit(0);
}
// 启动录像 (start ShareRec)
private void startRecorder() {
if (recorder.isAvailable()) {
recorder.setOnRecorderStateListener(this);
recorder.startRecorder();
// 如果您不知道什么时候您的画面会刷新,则可以使用下面的方式,让录像模块自动抓图,
// 否则可以调用onTheEndOfTheFrame()方法来手动驱动录像模块抓图 (If you don't know
// when your view will refresh, you can use the following way, let ShareRec
// capture the frame automatically. or you can call onTheEndOfTheFrame()
// manually when your frame refreshing)
recorder.startAuotRefreshRate(15);
} else {
Toast.makeText(this, R.string.not_availiable, Toast.LENGTH_SHORT).show();
}
}
// 停止录像 (stop ShareRec)
private void stopRecorder() {
recorder.stopRecorder();
}
// 显示用户资料 (show user profile)
private void showProfile() {
recorder.showProfile();
}
public void onStateChange(Recorder recorder, int state) {
if (state == Recorder.STATE_STOPPED) {
// show share page
this.recorder.setText("Eraser Demo");
this.recorder.addCustomAttr("score", "5000");
this.recorder.addCustomAttr("name", "ShareRec Developer");
this.recorder.addCustomAttr("brand", "hehe!");
this.recorder.addCustomAttr("level", "10");
this.recorder.showShare();
}
}
}
2:配置文件
清单文件配置
<activity
android:name="com.mob.tools.MobUIShell"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:windowSoftInputMode="stateHidden|adjustResize" />
初始化:key和server在Sharesdk中找到并且配置好
final SystemRecorder recorder = new SystemRecorder(MainActivity.this, "key", "server");
// 设置视频的最大尺寸
recorder.setMaxFrameSize(Recorder.LevelMaxFrameSize.LEVEL_1280_720);
// 设置视频的质量(高、中、低)
recorder.setVideoQuality(Recorder.LevelVideoQuality.LEVEL_HIGH);
// 设置视频的最短时长
recorder.setMinDuration(10 * 1000);
// 设置视频的输出路径
recorder.setCacheFolder("/sdcard/ShareREC/cvr");
recorder.isAvailable();
找到控件 在相应的控件下执行对应的方法:
开始:
停止:
展示:
直接贴代码
public class MainActivity extends Activity implements OnClickListener, OnRecorderStateListener {
private ViewRecorder recorder;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 初始化UI (init UI)
setContentView(R.layout.main_activity);
findViewById(R.id.btnStart).setOnClickListener(this);
findViewById(R.id.btnStop).setOnClickListener(this);
findViewById(R.id.btnProfile).setOnClickListener(this);
// 初始化ShareRec (init ShareRec)
View view = findViewById(R.id.evCan);
String appkey = "1e845b8c97a73";
String appsecret = "001a5c9908a814bfaf7568bfaca060a7";
recorder = new ViewRecorder(view, appkey, appsecret);
// 设置视频的最大尺寸
recorder.setMaxFrameSize(Recorder.LevelMaxFrameSize.LEVEL_1280_720);
// 设置视频的质量(高、中、低)
recorder.setVideoQuality(Recorder.LevelVideoQuality.LEVEL_HIGH);
// 设置视频的最短时长
recorder.setMinDuration(10 * 1000);
// 设置视频的输出路径
recorder.setCacheFolder("/sdcard/ShareREC/cvr");
recorder.isAvailable();
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnStart: startRecorder(); break;
case R.id.btnStop: stopRecorder(); break;
case R.id.btnProfile: showProfile(); break;
}
}
protected void onPause() {
// 暂停录像 (pause ShareRec)
recorder.pauseRecorder();
super.onPause();
}
protected void onResume() {
super.onResume();
// 恢复录像 (resume ShareRec)
recorder.resumeRecorder();
}
protected void onDestroy() {
super.onDestroy();
System.exit(0);
}
// 启动录像 (start ShareRec)
private void startRecorder() {
if (recorder.isAvailable()) {
recorder.setOnRecorderStateListener(this);
recorder.startRecorder();
// 如果您不知道什么时候您的画面会刷新,则可以使用下面的方式,让录像模块自动抓图,
// 否则可以调用onTheEndOfTheFrame()方法来手动驱动录像模块抓图 (If you don't know
// when your view will refresh, you can use the following way, let ShareRec
// capture the frame automatically. or you can call onTheEndOfTheFrame()
// manually when your frame refreshing)
recorder.startAuotRefreshRate(15);
} else {
Toast.makeText(this, R.string.not_availiable, Toast.LENGTH_SHORT).show();
}
}
// 停止录像 (stop ShareRec)
private void stopRecorder() {
recorder.stopRecorder();
}
// 显示用户资料 (show user profile)
private void showProfile() {
recorder.showProfile();
}
public void onStateChange(Recorder recorder, int state) {
if (state == Recorder.STATE_STOPPED) {
// show share page
this.recorder.setText("Eraser Demo");
this.recorder.addCustomAttr("score", "5000");
this.recorder.addCustomAttr("name", "ShareRec Developer");
this.recorder.addCustomAttr("brand", "hehe!");
this.recorder.addCustomAttr("level", "10");
this.recorder.showShare();
}
}
}