int fd,id,status;
// 打开声音设备
fd = open("/dev/dsp", O_RDONLY);
if (fd < 0) {
perror("open of /dev/dsp failed");
exit(1);
}
printf("fd = %d\n", fd);
id = open("/usr/share/sounds/phone.wav",O_RDONLY);
if (id < 0) {
perror("open of /usr/share/sounds/phone.wav failed");
exit(1);
}
printf("id = %d\n", id);
status = read(id, buf, sizeof(buf)); // 录音
printf("status = %d\n", status );
status = write(fd, buf, sizeof(buf)); // 回放
printf("status = %d\n", status );
打开声音设备和声音文件都正确,read()调用也成功,但write()总是调用失败,返回-1,请问write()怎么输出声音?linux下还有什么方法可以播放声音?