|
一个Linux下的CD播放程序,不知道为什么不能成功播放CD,请高手帮忙看一下,十分感谢
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/cdrom.h>
/*CD驱动器对应的设备文件*/
#define DEVICE "/dev/cdrom"
int
main ()
{
int fd;
int status;
int start_min, start_sec, start_frame; /*播放起始地址 */
int end_min, end_sec, end_frame; /*播放结束地址 */
struct cdrom_tocentry entry; /*TOC条目 */
struct cdrom_msf region; /*播放区域*/
/*打开设备*/
fd = open (DEVICE, O_RDONLY);
if (fd < 0)
{
perror ("unable to open" DEVICE);
exit (1);
}
/*计算播放起始点的地址*/
entry.cdte_track = 1;
entry.cdte_format = CDROM_MSF; /*采用MSF格式地址*/
status = ioctl (fd, CDROMREADTOCENTRY, &entry);
if (status != 0)
{
perror ("CDROMREADREADTOCENTRY ioctl failed");
exit (1);
}
start_min = entry.cdte_addr.msf.minute;
start_sec = entry.cdte_addr.msf.second;
start_frame = entry.cdte_addr.msf.frame;
/*计算播放结束点的地址*/
entry.cdte_track = 2;
status = ioctl (fd, CDROMREADTOCENTRY, &entry);
if (status != 0)
{
perror ("CDROMREADREADTOCENTRY ioctl failed");
exit (1);
}
start_min = entry.cdte_addr.msf.minute;
start_sec = entry.cdte_addr.msf.second;
start_frame = entry.cdte_addr.msf.frame;
/*指明播放区域*/
region.cdmsf_min0 = start_min;
region.cdmsf_sec0 = start_sec;
region.cdmsf_frame0 = start_frame;
region.cdmsf_min1 = end_min;
region.cdmsf_sec1 = end_sec;
region.cdmsf_frame1 = end_frame;
/*播放*/
status = ioctl (fd, CDROMPLAYMSF, ®ion);
if (status != 0)
{
perror ("CDROMPLAYMSF ioctl failed");
exit (1);
}
/*关闭设备*/
status = close (fd);
if (status != 0)
{
perror ("unable to close" DEVICE);
exit (1);
}
return 0;
} |
|