c# - 如何通过声音播放器传递字符串变量?
问题描述
我正在尝试将文件位置从我的列表框中传递到我的声音播放器中。
string fileLocation = listBox1.ToString();
SoundPlayer splayer = new SoundPlayer(soundLocation: fileLocation);
splayer.Play();
调试将变量显示为“C:\Temp\Sample1.wav”。
错误返回为“System.NotSupportedException:'不支持给定路径的格式。'”
谁能告诉我我在这里做错了什么?
解决方案
破解它!您需要拉出对象,然后将其转换为字符串。
object fileLocationobj = listBox1.Items[0];
string fileLocation = fileLocationobj.ToString();
SoundPlayer splayer = new SoundPlayer(soundLocation: fileLocation);
splayer.Play()
推荐阅读
- npm - 分离yaml文件并传入变量
- sql - 使用什么作为我的默认值来实现正确的 laravel 选择在哪里?
- html - 如何将文本与 CSS 相对对齐?
- c# - 为什么我的 Unity3D 精灵在我的 iPhone 上渲染时看起来像素化?
- f# - 如何实现策略模式以返回声明为私有的结构?
- c++ - Qt 应用程序部署不起作用。缺少入口点和 dll
- javascript - JavaScript:意外的结果得到该月剩余的天数
- java - 对android项目的结构和MVC模式感到困惑
- u-sql - 在 USQL 中解析多个日期时间
- angularjs - AngularJS 表单验证在表单外的 href 链接上触发