diff --git a/src/xpdev/xpbeep.c b/src/xpdev/xpbeep.c
index 7a677de8e7373fb1793b9db500f436b2996237f0..3c83871db346961ae28f8dada81e43d596bf8d47 100644
--- a/src/xpdev/xpbeep.c
+++ b/src/xpdev/xpbeep.c
@@ -936,17 +936,21 @@ do_xp_play_sample(const unsigned char *sampo, size_t sz, int *freed)
 		int ret;
 		int written=0;
 
-		alsa_api->snd_pcm_prepare(playback_handle);
-		while(written < sz) {
-			ret=alsa_api->snd_pcm_writei(playback_handle, samp+written, sz-written);
-			if(ret < 0) {
-				if(written==0) {
-					/* Go back and try OSS */
-					xptone_close_locked();
-					alsa_device_open_failed=TRUE;
-					xptone_open_locked();
+		while (written < sz) {
+			ret = alsa_api->snd_pcm_writei(playback_handle, samp + written, sz - written);
+			if (ret < 0) {
+				if (alsa_api->snd_pcm_prepare(playback_handle) == 0) {
+					ret = 0;
+				}
+				else {
+					if (written == 0) {
+						/* Go back and try OSS */
+						xptone_close_locked();
+						alsa_device_open_failed = TRUE;
+						xptone_open_locked();
+					}
+					break;
 				}
-				break;
 			}
 			written += ret;
 		}