public class AutoPlayer extends Activity {
private VideoView vv1=null;
private TextView tv1 = null;
private Timer timer = new Timer(true);
private Timer timer2 = new Timer(true);
private String result = null;
private int count= 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vv1=(VideoView)findViewById(R.id.VideoView01);
tv1=(TextView)findViewById(R.id.TextView01);
vv1.setVideoPath("/mnt/sdcard/Video/bx1.mp4");
//vv1.setVideoURI(Uri.parse("http://10.85.185.116:8088/myIIS/bx2.mp4"));
vv1.requestFocus();
vv1.start();
timer.schedule(task,2000, 2000); //延时1000ms后执行,1000ms执行一次
}//onCreate
TimerTask task = new TimerTask(){
public void run() {
count++;
Message message = new Message();
if(count<5)
{
if(vv1.isPlaying())
{
message.what = 1;
handler.sendMessage(message);
}
else
{
message.what = 0;
handler.sendMessage(message);
}
}
else
{
if(count<20)
{
message.what = 5;
handler.sendMessage(message);
}
else
{
message.what = 20;
handler.sendMessage(message);
}
}
}
};
final Handler handler = new Handler(){
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
tv1.setText("正在播放");
break;
case 0:
tv1.setText("没有播放");
break;
case 5:
//vv1.stopPlayback();
//vv1.seekTo(60000);
//vv1.start();
tv1.setText("seekTo 120*1000");
break;
case 20:
//timer.cancel();
WriteSettings("视频播放<br>seeekto<br>播放完毕<br>");
AutoPlayer.this.finish();
}
super.handleMessage(msg);
}
};
public void WriteSettings(String data)
{
FileOutputStream fOut = null;
OutputStreamWriter osw = null;
try{
fOut = openFileOutput("lee.txt",MODE_PRIVATE);
osw = new OutputStreamWriter(fOut);
osw.write(data);
osw.flush();
//Toast.makeText(context, "Settings saved",Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
e.printStackTrace();
//Toast.makeText(context, "Settings not saved",Toast.LENGTH_SHORT).show();
}
finally {
try {
osw.close();
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}//class
自Android 2.2开始,vold又做了大改动,升级为vold 2.0,之前的配置文件是
system/etc/vold.conf,vold 2.0变为system/etc/vold.fstab。
在init.rc中启动VOLD这个守护线程和创建socket的命令如下:
service vold /system/bin/vold
socket vold stream 0660 root mount
ioprio be 2
2、配置vold.fstab
vold.fstab文件的格式是:
Format: dev_mount <label> <mount_point> <part> <sysfs_path1...>
label: -Label for the volume
mount_point -Where the volume will be mounted
part -Partition #(1 based), or 'auto' for first usable partition.
<sysfs_path> -List of sysfs paths to source devices
例如:
dev_mount sdcard /mnt/sdcard 1 /devices/platform/mxsdhci.0/mmc_host/mmc0
自Android 2.2后,SD mount的位置变为/mnt/sdcard。
packages/apps/Settings/src/com/android/settings/deviceinfo/Memory.java
Vold上层MountService的代码位于:
frameworks/base/services/java/com/android/server/MountService.java
Vold底层处理的代码位于:
system/vold/
1、Vold设计架构
Setting
|
MountService
|
CommandListener
|
VolumeManager - NetlinkManager
|
Volume - DirectVolume
|
SD/USB device
MountService会接收来之Setting的变化,及来自底层VolumeManager的信息,并对之分析判,然后
Vold初始化时,会创建class NetlinkManager和VolumeManager,class NetlinkManager接收
来自底层的信息,然后传交给VolumeManager处理;
重要类class VolumeManager 仅有一个实例,它主要负责vold的管理操作,管理多个sd卡,usb各种
VolumeManager处理信息后,或报告给上层MountService,或交给volume执行具体操作(挂载
2、Vold代码实现过程大致分为三步:
1).创建链接:
在vold作为一个守护进程,一方面接受驱动的信息,并把信息传给应用层;另一方面接受上层的命令并
所以这里的链接一共有两条:
(1)vold socket: 负责vold与应用层的信息传递;
(2)访问udev的socket: 负责vold与底层的信息传递;
这两个链接都是在进程的一开始完成创建的。
这里主要是在vold启动时,对现有外设存储设备的处理。首先,要加载并解析vold.fstab,
并检查挂载点是否已经被挂载(注:这里检查挂载点的用意不是很清楚!); 其次,执行MMC卡挂
这里通过对两个链接的监听,完成对动态事件的处理,以及对上层应用操作的响应。
// From: http://www.cocoadev.com/index.pl?BaseSixtyFour
+ (NSString*)base64forData:(NSData*)theData {
const uint8_t* input = (const uint8_t*)[theData bytes];
NSInteger length = [theData length];
static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
uint8_t* output = (uint8_t*)data.mutableBytes;
NSInteger i;
for (i=0; i < length; i += 3) {
NSInteger value = 0;
NSInteger j;
for (j = i; j < (i + 3); j++) {
value <<= 8;
if (j < length) {
value |= (0xFF & input[j]);
}
}
NSInteger theIndex = (i / 3) * 4;
output[theIndex + 0] = table[(value >> 18) & 0x3F];
output[theIndex + 1] = table[(value >> 12) & 0x3F];
output[theIndex + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '=';
output[theIndex + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '=';
}
return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];
}