cocos2d-iphone 1.0.1.
I have noticed this with other cocos2d-iphone games installed in my device, like Kingdom Rush.
Basically, most of the times, the audio is fine (almost always). But suddenly, at an unexpected moment, the background music stops playing and only the sound effects work. Sometimes, killing the application will not be enough to fix it.
With my cocos2d-iphone game this happens as well, with no hint in the console. I use SimpleAudioEngine to play background music and sound effects.
Killing my application, restarting Xcode will not fix it. I usually just ignore the problem and, in the near future, it is suddenly gone. I suspect that rebooting the device tends to fix this, but that's beyond the point: I should know why is it happening.
I also tried preloading my background music. Doesn't change a thing.
I believe I have experienced this problem with both .mp3 and .wav formats.
Why might this be happening?
No idea to the exact reason, but I can think of a few:
memory warning causes audio stream to be interrupted
audio interruptions (calendar notification, incoming SMS/call) not handled properly by CocosDenshion
other streaming music is played (ie perhaps videoplayer, iPod music player)
music isn't streamed but buffered, which means music is fighting over audio buffers with all other effects - eventually so many audio effects are played that older buffers have to cancel playback (which might be the music) in order to allow the new effect to play
defective device (since it happens in other apps …)
bug in CocosDenshion (check the cocos2d issue tracker and forum for any unresolved audio bugs)
I think you can exclude the latter if you're using the playBackgroundMusic API to stream music instead of buffering it.
Related
Problem I need help with
Assist with optimizing latency in its "Short-Video Feed" and solving intermittent performance bugs. A central feature of my app requires seamless plays 15 to 60 second clips when users use "swipe up" hand gestures similarly to TikTok and Instagram reels. Right now, I have performance bugs (intermittent) such as black screens, delayed loading screens, sometimes long loading, etc.
The bugs may be caused because Flutter is slower than Native iOS. However, our "Short-Video Feed" has lots of bugs whether I use a M3U8 (Mux), or whether I use a MP4 based approach with AWS S3.
If I use the Mux based approach with M3U8, "Short-Video Feed" there is a noticeable few milliseconds black screen for each short-video playback.
If I use the Amazon based approach with MP4, "Short-Video Feed" intermittently loads for a few seconds (sometimes minutes) when there is low bandwidth, and some videos get stuck even when a user returns to a location with faster bandwidth.
Open issue on Flutter
https://github.com/flutter/flutter/issues/25558
Approaches I have tried with no success:
Native Player. I tried to use a native video player for Android/iOS, with MP4 and M3U8, but the UI was still very laggy (because of data transfer between Android/iOS and flutter latenices).
Flutter Player. I tried to use a Flutter video player for Android/iOS, with MP4 and M3U8, but the UI shows a black screen with M3U8 & heavy loading for poor internet connections with MP4.
Approaches I need help to try:
Optimize M3U8 player to minimize the black screen issue. or...
Create MP4 chunks to optimize for poor reception areas (this is what I think TikTok Instagram Reels, and similar applications do based on what I can see).
Has anyone solved this issue?
How about isolating whether these lags are due to network buffering or due to Flutter (or even a device hardware limitation such as memory or GPU)?
Perhaps use a few local MP4 files with identical frame rates and encoding parameters (both video and audio) and see whether the UI lag is reproducible upon swipe-up scrolling?
I have a project that uses libmpv with the opengl widget (as per the examples that come with libmpv) along with a QtWebEngine widget that displays information, graphics and animations (a scrolling ticker for example).
I found that of the video playback options in Qt, mpv was the smoothest and most reliable. It will play back perfectly smoothly any video up to 1080p.
However while video is playing, any animations in QtWebEngine are unsmooth and jittery. Video is also slightly less smooth when something is moving in the webpage.
The system I'm testing with is not struggling for resources (cpu use is around 45%). There is also not any video decoding, as it's playing back raw video (but while it plays back encoded video, the effect is the same, regardless if hardware acceleration is enabled or not).
I figure that the mpv widget is interrupting the MainWindow thread while it processes frames and causing it to freeze every few milliseconds.
As far as I know there is no way to separate the mpv thread from the MainWindow thread though.
I don't know if it'll be possible to make mpv and webengine work together smoothly. I feel like there must be some way to run two widgets at once in one window and not have them mess with each other.
I'm testing with Ubuntu 18.04, QT 5.11 and the latest mpv from git.
Does anyone have any advice or pointers for what to try first? I realise this is somewhat of a broad question but my knowledge of graphics is limited. If anyone has advice on a conceptual level (I don't need someone to code me a fix) I can investigate myself.
Thank you.
I am writing an application which will allow the user to scrub through an open video. Developing on Windows 7/8 with Qt 5.3, I have been using QMediaPlayer and QVideoWidget following the qvideowidget example project. The result has been pretty good, except that the QVideoWidget seems only to update during idle time. Still, it's a good start and it's usable.
However, when I build on Mac OS 10.10 (again with Qt 5.3), scrubbing behaves as though there were only one frame per second in the video. As I drag the "position" slider, the video jumps from one frame to the frame one second later, then one second after that, even though I am calling QMediaPlayer::setPosition several times with positions between those two frames.
The problem can be reproduced using the videowidget example that ships with Qt 5.3 here: Qt\Examples\Qt-5.3\multimediawidgets\videowidget. When the slider is dragged on a Windows machine, the QVideoWidget moves between frames that are spaced fairly close together. When the slider is dragged on a Mac (at least on mine), the QVideoWidget jumps between frames spaced about one second apart. No matter how long I wait for an "in between" frame to render, it won't happen unless I hit the "play" button.
I've tried calling QMediaPlayer::play() and QMediaPlayer::pause() one after the other to force an update, but this doesn't seem to work--QMediaPlayer works asynchronously, so the update doesn't have time to take effect.
If I check the value of QMediaPlayer::position, I find that it actually doesn't change between these jumps. It appears that when I call QMediaPlayer::setPosition, it is actually rounding the position to one second increments on a Mac and finer increments on a Windows machine.
Ideally, I would like to jump to a particular position in the video and render that frame immediately on the QVideoWidget. Is there any way to force QMediaPlayer to set the position accurately and update the associated QVideoWidget? Is there a better way to implement smooth scrubbing in a video?
Thanks for your help!
In case anyone else has a similar problem...
My best guess is that the issue stems from limitations in the codec used by QMediaPlayer, since this seems to be the main difference between the two platforms. Rather than deal with the codec issues directly, I looked around for other options.
MLT (http://www.mltframework.org/) seemed promising, but it is a major pain to compile and the primary author seems to have settled on offering SDK support to commercial users only.
libVLC (https://wiki.videolan.org/LibVLC/) looks a lot better. In particular, I’ve been using vlc-qt (https://github.com/ntadej/vlc-qt). The latter has an interface that will look quite familiar to users of QMediaPlayer and QVideoWidget. It was an easy replacement in my own application, and the result was much smoother video scrubbing on both Windows and Mac.
Hope this helps someone else!
I am using XAudio2 to play sounds in my game. I have about 16 source voices out of which 3 are looping effects which need to be played just like a background music. I have another background music which starts playing at regular intervals(once completed it waits for 1 minute and restarts). Whenever another effect has to be played like button click, gun shot etc, I search for an available source and attach the buffer to it and starts playing.
My problem is once the background music has started playing, just the looping effects will get played and other effects which need to be played on game actions(such as button click) do not get played. And all of these delayed effects get played once the background music is stopped. Also if I use one looping effect(instead of 3) all these get played in the right order.
I am using a submix voice for effects and background music is submitted directly to the mastering voice.
Can someone please help me as I am stuck here
Whenever one intends to play different sounds in the same time, he or she should make sure that these sounds are not in a queue, displayed in a sequential order, but they are displayed using different threads.
In Milsim's case the problem was exactly this, apparently, he used tasks to display the sounds, but they were not issued in different threads. He solved his problem using IAsyncAction.
Background:
My background music is being played as a sound effect because I want to change the pitch between each repetition of the tune.
The Issue:
While the background music is playing there's a lot of other short sound effects happening. After a certain number of sound effects play, my background music (also a sound effect) cuts out. The queue seems to cycle so that after say 50 sound effects have played, when the 51st plays, the 1st will be released whether it has completed or not.
Request for direction:
There are two directions I can see possibly going with this issue.
1. Not play the background music as an effect and figure out how to change the pitch as background music instead of an effect
2. Some how make sure that the effect will be retained until it has completed.
Thanks
The SimpleAudioEngine doesn't allow you to control channels, so it'll just play your sound effects in one of the channels it has allocated internally. Eventually all channels are playing audio. In that case, when a new audio file is to be played and all channels are already playing, SimpleAudioEngine will cancel one of the existing audio files. On occasion this will be your background music. Dang.
What you normally do to fix this is to assign (allocate) one audio channel specifically for the background music. No other audio will ever attempt to play audio on that channel. You will have to use the "regular" CocosDenshion API. It looks like you either need to use CDAudioManager or CDSoundEngine, but I have no experience with using channels with CocosDenshion.
Personally I never used CocosDenshion, whenever I needed more control I found the ObjectAL API to be easier to understand and it has excellent documentation. I made the following helper function for ObjectAL that plays a sound on a particular channel. I simply instantiated a ALChannelSource for my background music, and only played background music through that channel. The returned ALSoundSource even allows you to change pitch, pan, etc. while the audio is playing.
+(id<ALSoundSource>) playEffect:(NSString*)effect channel:(ALChannelSource*)channel loop:(bool)loop
{
id<ALSoundSource> soundSource = nil;
if (channel)
{
ALBuffer* buffer = [[OALAudioSupport sharedInstance] bufferFromFile:effect];
soundSource = [channel play:buffer loop:loop];
}
return soundSource;
}
All other audio files I'm playing through the OALSimpleAudio class.