【问题标题】:System.Media.SoundPlayer throws FileNotFoundException in .NetSystem.Media.SoundPlayer 在 .Net 中抛出 FileNotFoundException
【发布时间】:2021-03-17 16:01:50
【问题描述】:

尝试在我的应用程序中播放 .wav 文件以进行预览。

-> 正在执行以下代码:

System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = this.UnderlyingAudioFile.FullName;
player.Play();

发生错误:
System.IO.FileNotFoundException: '请确保指定位置存在声音文件。'

this.UnderlyingAudioFile.FullName;作为一个 System.IO.FileInfo 对象;

路径绝对正确。我检查了 3 次,可以从 this.UnderlyingAudioFile.FullName 复制粘贴它;

【问题讨论】:

    标签: filenotfoundexception system.io.file soundplayer


    【解决方案1】:

    当其他线程无法访问文件时,实际发生此错误。

    就我而言,我必须使用 fileshare.read 属性打开文件:

    this.Reader = new BinaryReader(File.Open(path,FileMode.Open,FileAccess.Read,FileShare.Read));
    

    【讨论】:

      猜你喜欢
      • 2020-02-08
      • 1970-01-01
      • 2012-06-19
      • 2020-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多