?? subchannel.c
字號:
/* * 代碼清單8: subchannel.c */#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <fcntl.h>#include <sys/ioctl.h>#include <linux/cdrom.h>/* CD驅動器對應的設備文件 */#define DEVICE "/dev/cdrom"/* 返回CD當前狀態的字符串 */char* audiostatus(int status) { switch(status) { case CDROM_AUDIO_INVALID: return "Invalid"; case CDROM_AUDIO_PLAY: return "Playing"; case CDROM_AUDIO_PAUSED: return "Paused"; case CDROM_AUDIO_COMPLETED: return "Completed"; case CDROM_AUDIO_ERROR: return "Error"; case CDROM_AUDIO_NO_STATUS: return "Stopped"; defautl: return "Unknown"; }} int main() { int fd; int status; struct cdrom_subchnl channel; /* 打開設備 */ fd = open(DEVICE, O_RDONLY); if (fd < 0) { perror("unable to open " DEVICE); exit(1); } while(1) { /* 讀取子通道數據 */ channel.cdsc_format = CDROM_MSF; /* 采用MSF格式地址 */ status = ioctl(fd, CDROMSUBCHNL, &channel); if (status != 0) { perror("CDROMSUBCHNL ioctl failed"); exit(1); } /* 輸出CD的當前狀態 */ printf("Status: %s \n", audiostatus(channel.cdsc_audiostatus)); printf("Track: %d \n", channel.cdsc_trk); printf("Postion: %02d:%02d:%02d(%02d:%02d:%02d) \n\n", channel.cdsc_reladdr.msf.minute, channel.cdsc_reladdr.msf.second, channel.cdsc_reladdr.msf.frame, channel.cdsc_absaddr.msf.minute, channel.cdsc_absaddr.msf.second, channel.cdsc_absaddr.msf.frame); fflush(stdout); usleep(100000); } /* 關閉設備 */ status = close(fd); if (status != 0) { perror("unable to close " DEVICE); exit(1); } return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -