Following is my code to load audio (for both iOS and Android) using just_audio. Using most of the code from the just_audio example.
Future<void> setAudio() async {
final session = await AudioSession.instance;
await session.configure(const AudioSessionConfiguration.speech());
// Listen to errors during playback.
_player.playbackEventStream.listen((event) {
print('JustPlayerAudio :: Loading Audio...${event.processingState}');
}, onDone: () {
print('JustPlayerAudio :: Loading Completed...');
}, onError: (Object e, StackTrace stackTrace) {
print('JustAudioPlayer :: Stream error occurred: $e');
});
// Try to load audio from a source and catch any errors.
try {
if (widget.asset != null) {
print('JustAudioPlayer :: setAudio : Asset being loaded...');
await _player
.setAudioSource(AudioSource.uri(Uri.file(widget.asset!.path)));
} else {
print('JustAudioPlayer :: setAudio : Url being loaded...');
await _player.setAudioSource(AudioSource.uri(Uri.parse(widget.url!)));
}
} catch (e) {
print("Error loading audio source: $e");
}
}
On iOS, first time I load a music file from device, it produces the following log
It looks like the audio was not loaded, but when I click the play button, the file plays and the log continues as below:
Now, if I attempt to repeat the loading of another file, the below happens:
And this time, the Audio play control goes into loading (CircularProgressIndicator) state. If I hot reload, the old songs plays.
The concerns I have is, loading errors are being thrown in two different places for two different attempts. How to avoid this "Cannot Open" error when its not really an error. And how to update player state when Stream error occurs.
Related
I keep getting this error when i try to play an audio from my local backend or an already uploaded audio from a site.
No matter what file format, this is what I get and this only happens with ios
error: Possible Unhandled Promise Rejection (id: 0): Error: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain". Error: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain".
error image
const player = new Audio.Sound();
player.loadAsync({ uri: url }, initialStatus).then(() => {
player.playAsync().then((playbackStatus) => {
if (playbackStatus.error) {
handlePlaybackError(playbackStatus.error);
}
});
});
After adding more error handling, I found out the error comes from loadAsync and it only happens when I try to play an audio from my local backend server. (ex: http://127.0.0.1:8000/media/audios/2021/08/08/27/21/filename.mp4)
It would be really great if I could get help on this, thanks in advance!
Update: Provided more code
So I found out that the that warning was being generated and preventing my audio files from playing because they are stored in my local server and for some reason the expo Audio.Sound object had an issue loading them, so I had to install expo-file-system, use the FileSystem to read download the file and use the uri produced from the download.
Example:
import * as FileSystem from 'expo-file-system';
const splitUrl = url.split('/');
const lastItem = splitUrl[splitUrl.length - 1];
const { uri } = await FileSystem.downloadAsync(
url,
FileSystem.documentDirectory + lastItem
);
const source = { uri: uri }; //the source you provide to the loadAsync() method
loadAsync() returns a Promise, so you have to await it.
If this is not the problem you have to provide more code, please.
Here's the documentation, so use it like this:
const sound = new Audio.Sound();
try {
await sound.loadAsync(require('./assets/sounds/hello.mp3'));
await sound.playAsync();
// Your sound is playing!
// Don't forget to unload the sound from memory
// when you are done using the Sound object
await sound.unloadAsync();
} catch (error) {
// An error occurred!
}
And here's a simple snack I made, it works for me, you might want to consider error handling using try-catch:
Snack example
How i can hide the errors in browser console?
I don't know how to hide these errors in the browser, i am using axios with vuejs
The code is
login(user){
let formData = new FormData();
formData.set('username', user.username);
formData.set('password', user.password);
return this._http
.post(`${baseUrl}/api/auth/login`, formData)
}
this._http -> is the axios service
You can catch your error this way:
export default {
errorCaptured(err, vm, info) {
// err: error trace
// vm: component in which error occured
// info: Vue specific error information such as lifecycle hooks, events etc.
// TODO: Perform any custom logic or log to server
// return false to stop the propagation of errors further to parent or global error
handler
}
}
In my Fixture, I have an action that will start to download a file with browser. This worked very fine until the server will respond directly.
.expect(fs.existsSync(downloadsFolder()+'/export.xml')).ok()
But now I have some file the server need to create, and so a waiting time will occur. I tried to expand the function:
.expect(fs.existsSync(downloadsFolder()+'/export.xml')).ok('War wohl nicht erfolgreich',{ timeout: 300000 })
But the result is the same with a first tryout. I did some research and found:
async function CheckFileExistsWithTimeDelay(t, timeDelay, fileNameAndPath) {
for (var i = 0; i < timeDelay; i++) {
console.log('Waited for a total of ' + i.toString() + ' microseconds');
await t.wait(1);
if (fs.existsSync(fileNameAndPath)) {
// break;
return;
}
}
};
This also does not work. I think the watch file function blocks the Fs and so the browser cannot download the file (write the file). Also, this does not work:
async function waitForFile (path) {
for (let i = 0; i < 300; i++) {
if (fs.existsSync(path))
return true;
await t.wait(1000);
}
return fs.existsSync(path);
}
await t.expect(await waitForFile(downloadsFolder()+'/export.xml')).ok("War wohl nicht erfolgreich", { timeout: 300000 });
It looks like that the file download will fail until testcafe is waiting some time. If the file is downloaded directly everything is fine.
Is there any good example to wait for a downloaded file without blocking the fs?
It was requested so I add it here: The line where testcafe will get the command to download)
await t
.click(Selector('button').withText('Aktionen'))
.click(Selector('a').withText('Xml Exportieren'));
As I wrote. Immediately download works perfect. Until the download is delayed it fails. It looks like that some hook is hanging on the file and so chrome cannot download.
NEW INFO 1
The server will response exact 38,7 seconds after the download link was clicked. After I do this with testcafe I will get inside the browser window
If I use a real case, it means I will click on the link on the physical website the file is downloaded well after the 38 seconds. No error.
NEW INFO 2
I also tried to add a long .wait(150000) to the fixture and then check if the file exists. The browser tried to download the file in the background while waiting inside .wait(150000) loop. And also this is failed.
So I think it is proof that it is a Testcafe issue and not a node issue.
Here is the another example of how to wait for a downloaded file in test:
import { Selector } from 'testcafe';
import fs from 'fs';
const waitForFileDownloaded = (filePath, timeDelay) => new Promise(resolve => {
let i = 1;
const intervalId = setInterval(() => {
if (fs.existsSync(filePath)) {
clearInterval(intervalId);
resolve(true);
}
i++;
if (i > timeDelay) {
clearInterval(intervalId);
resolve(false);
}
}, 1000);
});
fixture `Downloading`
.page `https://github.com/DevExpress/testcafe`;
test('Test', async t => {
await t
.click(Selector('a').withText('218 releases'))
.click(Selector('a').withText('Source code'))
.expect(await waitForFileDownloaded('c:\\Users\\username\\Downloads\\testcafe-1.6.0.zip', 60)).ok();
});
Also could you please clarify if the downloading process is started after TestCafe clicked on the link (for example, using only await t.wait() with a big timeout)?
I'm trying to unpublish a video but keep getting the warning
"Video element paused, auto-resuming. If you intended to do this, use publishVideo(false) or subscribeToVideo(false) instead."
I'm unpublishing with:
clientPublisher.publishAudio(false);
clientPublisher.publishVideo(false);
clientSession.unpublish(clientPublisher, handleError);
The "streamDestoryed" function is firing so it seems like it should be unpublished. But if I subscribe to it using:
o.subscriber = clientSession.subscribe(stream, vid, {... subscribeToAudio: false...}, function(error) {
if (error) {
}
else {
o.subscriber.subscribeToAudio(false);
}
}
I still get audio. What exactly does this message mean and how do I stop publishing?
EDIT:
If I subscribe first WITHOUT audio, I can toggle it on and off and it works fine. However, if the client publishes and I don't set subscribeToAudio to false, I can no longer toggle the audio on and off... it's always on.
I am trying to fetch data from a simple get request using Titanium.Network.HTTPClient
Here is the code
var url = "http://www.appcelerator.com"; //Here i have my get api URL, i have also tried replacing the url with google.com
var client = Ti.Network.createHTTPClient({
// function called when the response data is available
onload : function(e) {
Ti.API.info("Received text: " + this.responseText);
alert('success');
},
// function called when an error occurs, including a timeout
onerror : function(e) {
Ti.API.debug(e.error);
alert('error');
},
timeout : 5000 // in milliseconds
});
// Prepare the connection.
client.open("GET", url);
// Send the request.
client.send();
But the app is crashing with error Uncaught TypeError: Cannot read property 'extendModel' of undefined, I am not using any model, It is a new project with the above mentioned code, nothing more.
Here is the screenshot of error
Please help!
EDIT
Configuration details:
Titanium Command-Line Interface, CLI version 5.0.13
Titanium SDK
version 6.0.4.GA
Node version v4.8.2
Please let me know if any further details required,