I wrote a test application to play '.wav' audio files using qt(latest version) on mac (OSX Yosemite Version 10.10.5). Here is the code from cpp file.
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
m_player = new QMediaPlayer(this);
connect(m_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(onMediaStatusChanged()));
connect(m_player, SIGNAL(positionChanged(qint64)), this, SLOT(onProgressed(qint64)));
m_player->setMedia(QMediaContent(QUrl("/Users/testUser/Library/Metal.wav")));
m_player->play();
}
Widget::~Widget()
{
}
void Widget::onProgressed(qint64 pos)
{
qDebug()<<"Position is:"<<pos;
}
void Widget::onMediaStatusChanged()
{
qDebug()<<"Media Status Changed:" << m_player->mediaStatus() << " " << m_player->error();
}
and here is the output I am getting
Media Status Changed: QMediaPlayer::LoadingMedia QMediaPlayer::NoError
[11:16:13.300] FigByteFlumeCustomURLOpen signalled err=-12936 (kFigByteFlumeError_BadState) (no provider) at /SourceCache/CoreMedia/CoreMedia-1562.240/Prototypes/FigHTTP/FigByteFlumeCustomURL.c line 1486
Media Status Changed: QMediaPlayer::InvalidMedia QMediaPlayer::FormatError
I don't understand why I am getting Format error and however, the same code (except the path of the track) in windows is working fine.
Is there a fix for QMediaPlayer on Mac or Should I be using other APIs to play .wav files?
Any help would be appreciated! Thanks.
I suspect the reason of the failure (or at least one of them) is that you are passing a file path to QUrl instead of a URL. So either you set "file:///Users/testUser/Library/Metal.wav" or you use QUrl::fromLocalFile("/Users/testUser/Library/Metal.wav").
Related
When I try to execute "play" with loop on file that not exist, I got exaption "stack_overflow".
I use Qt 5.15.2 and windows 7
playlist->addMedia(QUrl::fromLocalFile("not_exist"));
playlist->setPlaybackMode(QMediaPlaylist::Loop);
QMediaPlayer *music = new QMediaPlayer();
music->setPlaylist(playlist);
music->play();
Can I catch this exception or maybe I can use another way to run sound in the loop to exclude this problem?
You have to use the error signal of QMediaPlayer:
connect(music, QOverload<QMediaPlayer::Error>::of(&QMediaPlayer::error),
[music](QMediaPlayer::Error error){
qDebug() << error << music->errorString();
});
Output:
QMediaPlayer::ResourceError "Could not open resource for reading."
I am using net.schmizz.sshj.xfer.scp.SCPFileTransfer class to upload file from local to remote server. It is failing with following error:
net.schmizz.sshj.xfer.scp.SCPException: EOF while expecting response
to protocol message. Additional info: bash: -c: line 0: unexpected EOF while looking for matching
bash: -c: line 1: syntax error: unexpected end of file
This issue I am facing only when remote machine is Windows. For Linux machine it is successfully uploading.
I have tried following steps in my code.
1. Download a file from remote machine to local
2. Upload same file again back to remote.
It is failing in step 2.
#Override
public boolean upload(String localLocation, String remoteLocation) throws SSHClientException {
this.ensureConnected();
SCPFileTransfer scp = this.sshj.newSCPFileTransfer();
try {
scp.upload(localLocation, remoteLocation);
} catch (IOException e) {
log.error("Failed to copy file {} from local path at {} to remote location {} at {}" + remoteLocation,
hostname, localLocation, e);
return false;
}
return true;
}
Any leads will be really helpful.
Thanks.
I got the solution.
The remote file path that I have used looks like :
'/cygdrive/c/Program Files/XXX/'
The issue is "'" in the path. Removal of "'" from the path results successful upload of the file.
Thanks to all who gave me leads.
Thanks,
Shruti
I've copied a .bat-file from Qt-ressources to a file system and executed it.
After that I wanted to delete the file, but it fails in Qt. If fails also when I restart the application. However, the file can be removed in the file-explorer.
I tried QFile::remove as well as QDir::remove. Static as well as not-static versions - no effect.
I tried to call using native file-separator - didn't help either.
What is wrong with this code?
if ( QFileInfo( dataRootPath+"/backupdb.bat" ).exists() )
{
//debugger stepps in
QFile f( QFileInfo( dataRootPath+"/backupdb.bat" ).canonicalFilePath());
f.remove( );
}
I had the same problem copying file from resources to file system and trying to remove it after that. QFile::errorString() returns "Access denied". So it seems that resource file has some nasty permissions that are copied by QFile::copy. May be it's possible to change permissions but I used my own 2 functions to copy file:
bool copyTextFile(QString srcPath, QString dstPath)
{
QFile file(srcPath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return false;
return writeTextFile(QString::fromUtf8(file.readAll()), dstPath);
}
bool writeTextFile(QString data, QString dstPath)
{
QFile file(dstPath);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return false;
QTextStream stream(&file);
stream << data;
return true;
}
I change its permissions before remove it.
QFile::copy(":/res/1.txt", "D:\\1.txt");
QFile file("D:\\1.txt");
file.setPermissions(file.permissions() |
QFileDevice::WriteOwner |
QFileDevice::WriteUser |
QFileDevice::WriteGroup |
QFileDevice::WriteOther);
file.remove();
I encountered the same error, but in my case the posted solutions did not work. However, it turned out that I had created a std::ofstream object in my code, that was unclosed. Thus, this was keeping the source file open which prevented the copying on Windows.
When I used AndroidFFmpeg to play audio file (MP3 file), I got issue
header missing while seeking.
Video play is ok; error occurs only in mp3 file.
Anyone knows how to fix it?
I have a temporary solution to fix it. In mpegaudiodec.c, you comment out errors return:
header = AV_RB32(buf);
if (header>>8 == AV_RB32("TAG")>>8) {
av_log(avctx, AV_LOG_DEBUG, "discarding ID3 tag\n");
return buf_size;
}
if (ff_mpa_check_header(header) < 0) {
av_log(avctx, AV_LOG_ERROR, "Header missing\n");
//return AVERROR_INVALIDDATA; do not return errors
}
I am using gradle to download the selenium chrome driver from maven
webtestsCompile 'org.seleniumhq.selenium:selenium-chrome-driver:2.32.0'
I am trying to use this directly and I see that I get this error :
Caused by:
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list
I have looked up a couple of questions from stack-overflow and other places it requires me to set the value of the property webdriver.chrome.driver to the location where I have downloaded with some-thing like this :
System.setProperty("webdriver.chrome.driver", "path to chrome-driver");
I am wondering what is the best way to go about this ?
EDIT 1:
I verified the java.class.path a snippet of this path looks like this :
/home/bhavya/.gradle/caches/artifacts-26/filestore/org.seleniumhq.selenium/selenium-chrome-driver/2.32.0/jar/14a4e8e32a4129c682c67381f5d7bf11f2327e1/selenium-chrome-driver-2.32.0.jar
This looks like the selenium-chrome-driver is present in the java.class.path.
Edit 2 :
I would want the chrome driver to work irrespective of the operating system that I am using, currently I am on a ubuntu box but a lot of this will get tested on a windows box. When I hard coded the value of the webdriver.chrome.driver to the value in EDIT 1, I am facing the following issue :
java.lang.IllegalStateException: The driver is not executable: /home/bhavya/.gradle/caches/artifacts-26/filestore/org.seleniumhq.selenium/selenium-chrome-driver/2.32.0/jar/14a4e8e32a4129c682c67381f5d7bf11f2327e1/selenium-chrome-driver-2.32.0.jar
Edit 3 :
Task within which I am running the test suite --
task webs(type: Test, dependsOn: updateNodeModules) {
testClassesDir = sourceSets.webtests.output.classesDir
classpath = sourceSets.webtests.runtimeClasspath
def javaHomeBin = new File(System.getProperty("java.home"), "bin");
def javaExec = new File(javaHomeBin, "java").getAbsolutePath();
systemProperties['jar.path'] = jar.archivePath
if(project.hasProperty('url')){
println" url passed as variable is $url"
systemProperties["selenium.webdriver.url"] = "$url"
}
systemProperties["selenium.webbrowser.type"] = "firefox"
if(project.hasProperty('browser')){
println "the browser passed is $browser"
systemProperties["selenium.webbrowser.type"] = "$browser"
}
include '**/UserEditControllerWebTest.class'
doFirst {
println " iterator is $it"
def chrome=configurations.testRuntime.find {
it.name.contains("selenium-chrome-driver")
}.path
println " chrome driver path is $chrome"
systemProperties["webdriver.chrome.driver"]= "$chrome"
}
}
Assuming that you need to set this system property for your tests, you can do something like:
test.doFirst {
systemProperty "webdriver.chrome.driver",
classpath.find {
it.name.contains("selenium-chrome-driver")
}.path
}