I have a problem handling the end of file state of the axWindows Media Player and then open another frame in Visual C++
Here is my function :
private: System::Void axWindowsMediaPlayer1_PlayStateChange(System::Object^ sender, AxWMPLib::_WMPOCXEvents_PlayStateChangeEvent^ e) {
if (e->newState == 8) {
this->Hide();
MainForm^ frame = gcnew MainForm();
frame->ShowDialog();
}
}
If I build the project, the media player render the movie, plays it and when it reaches the end of file it's called the Hide function but the frame didn't show up. I receive no error.
What should I do or what I'm doing wrong ?
In this kind of situation you should try to catch an exception, and read its message - it's very helpful, and helps spare some time in the future.
try
{
...
}
catch (System::Exception^ e)
{
System::Console::WriteLine(e->Message);
}
Related
I'm using Heaps.io Game Engine for Haxe and currently trying to play sound WAV file from my resources every time a specific event happens. But it always plays only first time, then nothing. Code example:
import hxd.Event;
import hxd.System;
import hxd.Window;
import hxd.res.Sound;
class Main extends hxd.App {
var sound: Sound = null;
var window: Window;
function onEvent(event: Event) {
if (event.kind == EKeyDown) {
if (event.keyCode == hxd.Key.P) {
playSound();
}
if (event.keyCode == hxd.Key.Q) {
System.exit();
}
}
}
function playSound() {
trace(sound);
if (sound != null) {
sound.play();
}
}
override function init() {
hxd.Res.initEmbed();
window = Window.getInstance();
window.addEventTarget(onEvent);
if (Sound.supportedFormat(Wav)) {
sound = hxd.Res.pong;
}
}
override function update(dt: Float) {
}
public static function main() {
new Main();
}
}
After pressing 'P' for 7 times, pong.wav would play only once. After quitting by pressing 'Q', debug console shows this:
(7) src/Main.hx:22: pong.wav
AL lib: (EE) alc_cleanup: 1 device not closed
So it does see my sound file but can't play it for whatever reason. I've tried to write sound.stop(); before sound.play();, but to no avail. Could it be something about the last debug message?
Edit1: I've tried to use Channels, but result was still the same.
And in the code above it seems like no other sound file could be played after the first one as well.
P.S. There's even no such tag as "Heaps" on Stack Overflow.
Found solution: https://github.com/HeapsIO/heaps/issues/1100, and seems like it is a bug!
A simple fix is to put this line in your App.init
#:privateAccess haxe.MainLoop.add(() -> {});
E.g.
override function init() {
hxd.Res.initEmbed();
#:privateAccess haxe.MainLoop.add(() -> {});
window = Window.getInstance();
window.addEventTarget(onEvent);
if (Sound.supportedFormat(Wav)) {
sound = hxd.Res.pong;
}
}
Now sound is always working properly and problem solved.
As a side note, I still don't know what to think about the last waning message, it still occures but does nothing.
I am using Android camera2 to create a custom camera. The cameraDevice.close() method is slow and it makes UI freeze for 1 sec. I put it in another thread and it seems to work just fine. I want to know if this will cause some serious problem and whether there is another way to achieve this. Here is my closeCamera method:
private void closeCamera() {
boolean release = false;
try {
mCameraOpenCloseLock.acquire();
release = true;
} catch (InterruptedException e) {
release = false;
}
try {
preparing = true;
if (mCaptureSession != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && mCaptureSession.isReprocessable()
|| validCameraSession) {
mCaptureSession.close();
}
mCaptureSession = null;
validCameraSession = false;
}
} catch (IllegalStateException e) {
mCaptureSession = null;
} catch (Exception e) {
mCaptureSession = null;
}
try {
new Thread(new Runnable() {
#Override
public void run() {
if (mCameraDevice != null) {
if (openCamera) {
mCameraDevice.close();
mCameraDevice = null;
}
}
}
}).start();
} catch (IllegalStateException e) {
Log.e(TAG, "closeCamera: mCaptureSession - ", e);
} catch (Exception e) {
Log.e(TAG, "closeCamera: mCaptureSession - ", e);
}
if (release) {
if (mCameraOpenCloseLock != null) {
int lock = mCameraOpenCloseLock.availablePermits();
if (lock > 1) mCameraOpenCloseLock.release(lock - 1);
else if (lock == 0) mCameraOpenCloseLock.release();
}
}
}
I think it may cause crash when mCameraDevice has not been closed but user open camera again. But it is rare case, and I am thinking of putting another check before open camera again. I don't want my UI to freeze 1 sec for it to close, is there any other way I can achieve that except putting it in seperate thread?
As Alex Cohn mentions, the recommended practice is to do all camera-related work on a separate thread from the UI.
It also takes a long time to open the camera, or create a capture session, relatively speaking, so doing those operations not on the UI thread is also a good idea.
That said, as long as you're not losing track of your own app state (so that you don't try to use a camera device you've already closed by accident, for example), there's no reason you can't mix calls to the camera device or capture session from multiple threads. The classes themselves are thread-safe.
As far as I know, such freeze with cameraDevice.close() happens on some unfortunate devices, and sometimes is cured by performing a normal system upgrade.
But this is a little consolation if this happens to you, on your device. Actually, you are kind of lucky that you can prepare a fix for that. The end-users of your app will benefit from your misfortune.
Your code looks OK, if it delivers desired improvements for you. As I explained, it may be hard to reproduce this problem on another device.
I would rather put all closeCamera() logic on the same background thread. If you provided a Handler to openCamera(), as in the official example,
manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);
then I would suggest posting all closeCamera() sequence to this mBackgroundHandler.
Recently I am writing an app on My PC and lumia 640, everything seems good when it runs under Debug mode in VS 2015, but when I use it on my phone and tap a button to open a FileOpenPicker to choose picture from PicturesLibrary, it just crash...
When I try connecting my phone and use VS to find the problem, it never shows up any more...Also, when I run my app on my PC, whether under Debug mode or not, the problem also never happens.
The Listener of the button looks like this:
private async void OnSnap(object sender, RoutedEventArgs e)
{
try
{
FileOpenPicker fileOpenPicker = new FileOpenPicker();
fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
fileOpenPicker.FileTypeFilter.Add(".jpg");
fileOpenPicker.FileTypeFilter.Add(".png");
fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
var inputFile = await fileOpenPicker.PickSingleFileAsync();
if (inputFile == null)
{
// The user cancelled the picking operation
return;
}
else
{
Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(inputFile);
Frame frame = Window.Current.Content as Frame;
frame.Navigate(typeof(PictureChoosePage), await inputFile.OpenAsync(FileAccessMode.Read));
}
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message);
var msgDialog = new MessageDialog(exception.Message) { Title = "Unkown Error" };
msgDialog.Commands.Add(new Windows.UI.Popups.UICommand("OK", uiCommand => {
Frame frame = Window.Current.Content as Frame;
frame.Navigate(typeof(MainPage));
}));
msgDialog.Commands.Add(new Windows.UI.Popups.UICommand("Cancel", uiCommand => { }));
await msgDialog.ShowAsync();
return;
}
}
One more thing to mention is that when my App crash, the bottom bar of the FileOpenPicker shows up...like this:
The required permissions should have been declared, and if there is a UnathorizedAccessException thrown, it should be caught by my code...So I'm thinking if this is the bug of the OS since the windows 10 mobile on my lumia 640 is 10.0.14295.1000, just a preview version.
I want to make an application for cardboard with a sony actioncam. I noticed that we can get the video preview by a SurfaceView method. But I remember that the only way to have a split screen with the camera device is by a SurfaceTexture.
So my question is, is there a way with one actioncam to have 2 video previews simultaneously ( split screen ) ??
thanks
EDIT:
okay so I went ahead and bought an action cam AS200, the sdk sample worked perfectly and i was able to get the video preview very quickly. I tried to duplicate the SimpleStreamSurfaceView with no success as expected. Now I m trying to copy the byte array in order to have two previews in one array. First I have tried to simply create an arraybuffer where i put two times the bitmap array, just to see what changes ... and I was surprised to see that nothing changed ... Here is the code
`
while (mWhileFetching) {
try {
byte[] jpegData = mJpegQueue.take();
ByteBuffer test=ByteBuffer.allocate(jpegData.length *2);
test.put(jpegData);
test.put(jpegData);
frameBitmap = BitmapFactory.decodeByteArray(//
test.array(), 0, test.array().length, factoryOptions);
//frameBitmap.setWidth(frameBitmap.getWidth()*2);
} catch (IllegalArgumentException e) {
if (mInMutableAvailable) {
clearInBitmap(factoryOptions);
}
continue;
} catch (InterruptedException e) {
Log.i(TAG, "Drawer thread is Interrupted.");
break;
}
if (mInMutableAvailable) {
setInBitmap(factoryOptions, frameBitmap);
}
drawFrame(frameBitmap);
}
if (frameBitmap != null) {
frameBitmap.recycle();
}
mWhileFetching = false;
}
};
mDrawerThread.start();
return true;
}
`
Of course I wasnt expecting a great result but why nothing changed ??
I solved it. I just had to draw two times in the canvas to different rectangles.
I am trying to write code in J2ME for the Nokia SDK (S60 device) and am using Eclipse.
The code tries to play some wav files placed within the "res" directory of the project. The code is as follows:
InputStream in1 = null;
System.out.println("ABout to play voice:" + i);
try {
System.out.println("Getting the resource as stream.");
in1 = getClass().getResourceAsStream(getsound(i));
System.out.println("Got the resouce. Moving to get a player");
}
catch(Exception e) {
e.printStackTrace();
}
try {
player = Manager.createPlayer(in1, "audio/x-wav");
System.out.println("Created player.");
//player.realize();
//System.out.println("Realized the player.");
if(player.getState() != player.REALIZED) {
System.out.println("The player has been realized.");
player.realize();
}
player.prefetch();
System.out.println("Fetched player. Now starting to play sound.");
player.start();
in1.close();
int i1 = player.getState();
System.out.println("Player opened. Playing requested sound.");
//player.deallocate();
//System.out.println("Deallocated the player.");
}
catch(Exception e) {
e.printStackTrace();
}
}
Where the function getSound returns a string that contains the name of the file to be played. It is as follows:
private String getSound(int i) {
switch(i) {
case 1: return "/x1.wav";
case 2: return "/x2.wav";
}
}
My problem is this:
1. When I try to add more than 10 sounds, the entire application hangs right before the prefetch() function is called. The entire system slows down considerably for a while. I then have to restart the application.
I have tried to debug this, but have not gotten any solutions so far. It would be great if I could get some help on this.
The problem lies in the emulator being used for the project. In the emulation tab in the Run Configurations window, the following Device must be selected:
Group: Nokia N97 SDK v1.0
Device: S60 Emulator
Changing to the above from Devices listed under the Sun Java Wireless Toolkit solved the problem.