Closed bradrice closed 3 years ago
Can you provide the errors you see?
Here are the errors. However, the app does compile and it runs to the device.
`app/core/services/player.service.ts:496:42 - error TS2552: Cannot find name 'AVAudioSession'. Did you mean 'audioSession'?
496 const audioSession = AVAudioSession.sharedInstance();
app/core/services/player.service.ts:496:27
496 const audioSession = AVAudioSession.sharedInstance();
'audioSession' is declared here.
app/core/services/player.service.ts:497:51 - error TS2304: Cannot find name 'AVAudioSessionCategoryPlayback'.
497 audioSession.setCategoryError(AVAudioSessionCategoryPlayback);`
so you're calling native APIs in your application directly, to avoid TS
warnings which is what TS2552
is, you need to install the native typings so TS knows what you're doing since it's unaware of android/ios APIs.
That will resolve those warnings and let the compiler know that you know what you're doing 😄
So per the reference document on migrating to NS7
With the new @nativescript/types you can actually simplify your references.d.ts to this if you want both iOS and Android type declarations: (https://nativescript.org/blog/nativescript-7-announcement/)
I have done that but still getting the errors.
/// <reference path="./node_modules/@nativescript/types/index.d.ts" />
You can also include specific platform types as needed if you desire; for example, say you wanted different Android sdk types alongside the iOS types:
/// <reference path="./node_modules/@nativescript/types-ios/index.d.ts" />
/// <reference path="./node_modules/@nativescript/types-android/lib/android-29.d.ts"
Be sure to restart your IDE if you just added those, especially VSCode as it sometimes does not pick up changes like this.
The types are working in the plugin, so I'm certain it works and might just be your editor or a minor change missing.
The blog doesn't mention installing anything. Do I have to install a dependency?
@nativescript/types
should be a devDep, just as the older tns-platform-declarations
were used for typings.
Let me know if that helps.
OK, thanks. I do have it installed, I do have a references.d.ts file with thos lines in it, but for some reason it is not finding the declarations.
this might be a tsconfig issue to fix then, can you compare with the demo app on the repo here?
Thanks for your help Brad. I think I figured it out. I had my references.d.ts file at the root of my project, but my tsconfig wasn't including it at that level. So I added it to my "files" parameter and now it is finding it.
I get errors with these two lines of code when building for ios
const audioSession = AVAudioSession.sharedInstance(); audioSession.setCategoryError(AVAudioSessionCategoryPlayback);
Also, I'm having some problems with the player instantiating more than once and playing tracks over top of each other. Is there a way to make sure there is only one instance and only one track can play at once? Perhaps it is related to the issue above?