Since the JavaFx Media has not been ported to the Mobile Platforms yet, can anyone help me with using the native iOS APi's to play a sound mp3 file that would be stored in my main/resources folder in my gluon project.
相关问题
- I get an exception when trying to swap elements in
- JFX scale image up and down to parent
- Dragging an undecorated Stage in JavaFX
- JavaFX sample issue
- How to change the font size in ListView in JavaFX?
相关文章
- Low quality icon in taskbar of a Stage. JavaFX
- Loading custom font using JavaFX 8 and css
- Javafx Platform.runLater never running
- JavaFX scrolling table update performance degrades
- Javafx select multiple rows
- Escape from a Number TextField in a JavaFX dialog
- How to merge cells in JavaFX Scene builder?
- Adding view with constructor arguments to a border
While on Android we can easily add native API to the Android folders of a Gluon project (check this solution for using native Media on Android), the use of native code (Objetive-C) with the Media API on iOS folders is not enough, since it has to be compiled, and the compiled files have to be included into the ipa.
Currently, Charm Down is doing this for a bunch of services. If you have a look at the
build.gradle
script for iOS, it includes thexcodebuild
task to compile and build the native librarylibCharm.a
, that later should be included in any iOS project using any of those services.My suggestion will be cloning Charm Down, and providing a new service:
AudioService
, with some basic methods like:This service will be added to the
Platform
class:and you should provide implementations for Desktop (empty), Android (like the one here) and iOS.
IOS implementation - Java
You will have to add this to the
IOSPlatform
class:and create the
IOSAudioService
class:Finally, you will have to add the native calls in
CharmApplication
:IOS implementation - Objective-C
Now, on the native folder, on
CharmApplication.m
, add the implementation of those calls:and create the header file
Audio.h
:and the implementation
Audio.m
. This one is based on this tutorial:Build the native library
Edit the
build.gradle
for the iOS module, and add the Audio service to thexcodebuild
task:Build the project
Save the project, and from the root of the Charm Down project, on command line run:
If everything is fine, you should have:
Gluon Project
With those dependencies and the native library, you will be able to create a new Gluon Project, and add the jars as local dependencies (to the
libs
folder).As for the native library, it should be added to this path:
src/ios/jniLibs/libCharm.a
.Update the
build.gradle
script:On your View, retrieve the service and provide some basic UI to call the
play("audio.mp3")
,pause()
,resume()
andstop()
methods:Finally, place an audio file like
audio.mp3
, undersrc/ios/assets/audio.mp3
, build and deploy to iOS.Hopefully, this API will be provided by Charm Down any time soon. Also if you come up with a nice implementation, feel free to share it and create a Pull Request.