XNA 4 Song.fromUri 包含空格
嘿, 当尝试从我的 HDD (file:///...) 加载歌曲(通过 Uri)(Song.fromUri()
) 时,媒体播放器会抛出异常。 经过一番谷歌搜索后,我发现这个问题与 Uri 中的空格有关,所以我尝试转义它:
Uri.escapeUriString()
不起作用,结果是一个新的 Uri 对象,包含空值。 uri.escapeDataString() 或不同解决方案上的情况相同。
有没有更简单的方法将外部 mp3 加载到 XNA 中?
Hey,
When trying to load a Song (via Uri) (Song.fromUri()
) from my HDD (file:///...), The Mediaplayer throws a Exception.
After a bit of googling i found out, that this Problem is related to Spaces in the Uri, so i tried escaping it:
Uri.escapeUriString()
don't work, the Result is a new Uri Object, containing null. Same Thing on uri.escapeDataString()
or different Solutions.
Is there an easier way to load an external mp3 into XNA?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是使用反射来访问这个内部构造函数:
下面是一些执行此操作的代码:
显然这并不理想。我不认为 XNA 运行时会进行次要版本更新(这意味着如果您的游戏使用 XNA 4.0,它始终是相同的运行时),但我不确定。通过使用内部构造函数,您的游戏完全受 Microsoft 二进制更新的支配。您可能需要一个漂亮的大型异常处理程序。
此外,我发现某些 MP3 文件会(字面上)无提示地无法播放。此外,此方法显然没有填充
Duration
属性。(显然,这是仅限 Windows 的代码。但是无论如何,您都无法像在 WP7 或 Xbox 上那样真正访问文件系统的随机位。)
The simplest method would be to use reflection to get access to this internal constructor:
Here is some code that does just that:
Obviously this is not really ideal. I do not think the XNA runtime does minor-version updates (meaning that if your game uses XNA 4.0, it is always the same runtime), but I do not know for sure. By using an internal constructor your game is entirely at the mercy of binary updates by Microsoft. You probably want a nice big exception handler on that.
Additionally, I found that some MP3 files would (literally) silently fail to play. Also the
Duration
property is obviously not filled in by this method.(Obviously this is Windows-only code. But you can't really access random bits of the filesystem like this on WP7 or Xbox anyway.)