Reputation: 21
on my window forms I have created a button on my application. when I click the button it will check if there is any CD/DVD in the CD drive. If there is a CD/DVD in the CD drive, the media player will start the video media on windows media player i have add to the application.
So far, I have been only able to create the open dialog to select from the CD and play them. Can anyone advice me on what I should use to detect the CD media in the drive?
EDIT://sorry i am not great with C# so can you guys explain on the tutorials you provided?
private void Runbtn_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.currentPlaylist = axWindowsMediaPlayer1.mediaCollection.getByName("mediafile");
}
private void Stopbtn_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
}
}
Upvotes: 2
Views: 741
Reputation: 4671
The following code should work: (it is in C++, use DllImport to make Win32 API calls - explained here)
char szDrives[MAX_PATH];
long TotalNumberOfFreeBytes = 0;
long FreeBytesAvailable = 0;
// Get all the drives on your system. Divide by 4 as strlen("C:\") == 4
int noOfDrives =(GetLogicalDriveStrings(MAX_PATH,szDrives)/4);
for(int i=0;i<noOfDrives ;i++)
{
// find CD ROM drives
if (DRIVE_CDROM == GetDriveType(&drivestr[i*4]))
{
if(!GetDiskFreeSpaceEx(&drivestr[i*4],
&FreeBytesAvailable,
NULL,
&TotalNumberOfFreeBytes ))
{
// Disk in drive, enumerate files
// using FindFirstFile/FindNextFile
// and play video if any
}
}
}
The GetDiskFreeSpaceEx function returns zero (0) for TotalNumberOfFreeBytes and FreeBytesAvailable for all CD requests unless the disk is an unwritten CD in a CD-RW drive.
Upvotes: 1