Hi, I am trying to write a foreign code to allow audio recording. But i am facing a problem.
Hee is the code:
using Uno;
using Uno.UX;
using Uno.Collections;
using Fuse;
using Uno.Threading;
using Fuse.Scripting;
using Uno.Compiler.ExportTargetInterop;
using Uno.Permissions;
[UXGlobalModule]
[ForeignInclude(Language.Java,
“android.media.MediaPlayer”,
“android.media.MediaRecorder”,
“android.os.Bundle”,
“android.widget.Toast”,
“android.os.Environment”,
“java.io.IOException”)]
public class Audio: NativeModule{
public Audio(){
AddMember( new NativeFunction("RecordAudio", (NativeCallback)RecordAudio) );
AddMember( new NativeFunction("StopAudio", (NativeCallback)StopAudio) );
/*AddMember( new NativeFunction("playAudio", (NativeCallback)PlayAudio) );*/
}
object RecordAudio(Context c, object[] args){
string nomFichier="recordTest";
string outputFile = AudioRecordImplement.Record(nomFichier);
return outputFile;
}
object StopAudio(Context c, object[] args){
AudioRecordImplement.Stop();
}
/*object PlayAudio(string nomFichier){
}*/
public extern(Android) class AudioRecordImplement{
[Foreign(Language.Java)]
private MediaRecorder myAudioRecorder;
static extern(Android) string Record(string nomFichier)
@{
private String outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pyeple/Pyeple Audio/".nomFichier.".opus";
Activity a = com.fuse.Activity.getRootActivity();
try {
myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.DEFAULT);
myAudioRecorder.setOutputFile(outputFile);
myAudioRecorder.prepare();
myAudioRecorder.start();
} catch (IllegalStateException ise) {
// make something ...
} catch (IOException ioe) {
// make something
}
Toast.makeText(a, "Recording started", Toast.LENGTH_LONG).show();
return outputFile;
@}
[Foreign(Language.Java)]
static extern(Android) string Stop()
@{
myAudioRecorder.stop();
myAudioRecorder.release();
myAudioRecorder = null;
Toast.makeText(getApplicationContext(), "Audio Recorder successfully", Toast.LENGTH_LONG).show();
@}
[Foreign(Language.Java)]
static extern(Android) string play()
@{
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(outputFile);
mediaPlayer.prepare();
mediaPlayer.start();
Toast.makeText(getApplicationContext(), "Playing Audio", Toast.LENGTH_LONG).show();
} catch (Exception e) {
// make something
}
@}
}
}
here the error:
C:\Users\User\Documents\Fuse\Pyeple\Audio.uno(29.23): E3102: There is nothing named ‘AudioRecordImplement’ accessible in this scope. Are you missing a package reference?
C:\Users\User\Documents\Fuse\Pyeple\Audio.uno(29,24): Error E3102: There is nothing named ‘AudioRecordImplement’ accessible in this scope. Are you missing a package reference?C:\Users\User\Documents\Fuse\Pyeple\Audio.uno(34.3): E3102: There is nothing named ‘AudioRecordImplement’ accessible in this scope. Are you missing a package reference?
C:\Users\User\Documents\Fuse\Pyeple\Audio.uno(34,4): Error E3102: There is nothing named ‘AudioRecordImplement’ accessible in this scope. Are you missing a package reference?1,54 s