- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
当文件的路径+文件名很长时,我注意到了
PlaySound(fName.c_str(), NULL, SND_ASYNC);
有效,但无效
mciSendString((L"open \"" + fName + L"\" type waveaudio alias sample").c_str(), NULL, 0, NULL);
mciSendString(L"play sample", NULL, 0, NULL);
失败命令示例:
open "C:\qisdjqldlkjsqdjqdqjslkdjqlksjlkdjqsldjlqjsdjqdksq\dajdjqjdlqjdlkjazejoizajoijoifjoifjdsfjsfszjfoijdsjfoijdsoifoidsjfojdsofjdsoijfoisjfoijoisdjfosjfqsd\Windows Critical Stop.wav" type waveaudio alias sample
但是:
我确实需要 mciSendString 而不是 PlaySound(),因为 PlaySound() 不播放某些文件(48 khz 音频文件,有时是 24 位文件等)
我需要能够播放路径可能很长的音频文件,因为我的应用的最终用户可能拥有此类文件
如何让 mciSendString 接受长文件名?
注意事项:
我还尝试使用 mciSendCommand 来处理这个 MSDN 示例, 但都是一样的。
最大路径+文件名长度为 127(127:工作,128+:不工作)
如果真的不可能使 mci*
函数处理超过 127 个字符的文件名,我可以使用什么来代替,只需使用 winapi (没有外部库)? (PlaySound
不是一个选项,因为它不能真正处理所有 wav 文件,例如 48 khz:不工作等)
最佳答案
127 的限制看起来很奇怪。我没有在 MSDN 上找到任何关于它的信息。
有另一种语法可以打开:open waveaudio!right.wav
您可以尝试的一个选项是将工作目录更改为文件的目录,然后限制仅适用于文件名。 -> SetCurrentDiectory
要缩短文件名,可以使用 Winapi 函数 GetShortPathName
但是:
SMB 3.0 does not support short names on shares with continuous availability capability.
Resilient File System (ReFS) doesn't support short names. If you call GetShortPathName on a path that doesn't have any short names on-disk, the call will succeed, but will return the long-name path instead. This outcome is also possible with NTFS volumes because there's no guarantee that a short name will exist for a given long name.
基于 MSDN 的示例:
#include <string>
#include <Windows.h>
template<typename StringType>
std::pair<bool, StringType> shortPathName( const StringType& longPathName )
{
// First obtain the size needed by passing NULL and 0.
long length = GetShortPathName( longPathName.c_str(), NULL, 0 );
if (length == 0) return std::make_pair( false, StringType() );
// Dynamically allocate the correct size
// (terminating null char was included in length)
StringType shortName( length, ' ' );
// Now simply call again using same long path.
length = GetShortPathName( longPathName.c_str(), &shortName[ 0 ], length );
if (length == 0) return std::make_pair( false, StringType() );
return std::make_pair(true, shortName);
}
#include <locale>
#include <codecvt>
#include <iostream>
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
//std::string narrow = converter.to_bytes( wide_utf16_source_string );
//std::wstring wide = converter.from_bytes( narrow_utf8_source_string );
int main( int argc, char** argv )
{
std::wstring myPath = converter.from_bytes( argv[0] );
auto result = shortPathName( myPath );
if (result.first)
std::wcout << result.second ;
return 0;
}
关于c++ - 如果路径太长,mciSendString 将不会播放音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45221390/
在我们的服务出现一些预期的增长之后,突然间一些更新花费了非常长的时间,这些过去非常快,直到表达到大约 2MM 记录,现在它们每个需要大约 40-60 秒。 update table1 set fiel
我在服务中实现了一个传感器事件监听器,只要采样周期和最大报告延迟低于 1 秒,该监听器就可以正常工作,但一旦我将采样周期增加到超过 1 秒,传感器就根本不会更新。 我希望采样周期为 10 秒(可能是
我使用 Tkinter GUI 来启动测量和分析过程,基本上只需单击一个按钮即可开始。由于这些测量可能需要一段时间,我尝试添加一个进度条,即这个: http://tkinter.unpythonic.
我正在尝试使用套接字发送数据包,但出现错误。 invalid conversion from ‘omnetpp::cPacket*’ to ‘inet::Packet*’ [-fpermissive]
我刚刚发现 String#split 有以下奇怪的行为: "a\tb c\nd".split => ["a", "b", "c", "d"] "a\tb c\nd".split(' ') => ["a
您好,我正在尝试 ClojureScript,我正在使用 Klipse作为我的 REPL 差不多。这可能不是它的预期用途,但因为我没有做任何太复杂的事情,所以现在没问题。 我遇到的一个问题是尝试设置计
根据下面的数据,ClockKit 会生成一次 future 的 CLKComplicationTimelineEntry 项,但对于过去的时间点,会进行 24 次调用!这是为什么? 更多详情: 我注意
我有一个 MySQL 表,这个表有一个名为 datetime_utc 的 DATETIME 列。如您所料,它是 UTC 日期和时间。在我的 Bookshelf 模型中,我定义了一个虚拟 getter,
大家好,我是二哥呀! 昨天,一位球友问我能不能给他解释一下 @SpringBootApplication 注解是什么意思,还有 Spring Boot 的运行原理,于是我就带着他扒拉了一下这个注解的源
我是一名优秀的程序员,十分优秀!