Nativescript角保持应用程序在后台播放

时间:2020-05-27 09:53:38

标签: nativescript

[nativescript]如何保持本机脚本-角应用程序在IOS的后台运行。我有一个打开应用程序内浏览器的按钮,并且有一个播放音乐的网页,我希望在用户离开应用程序时继续播放音乐。

这是我的组件。

export class BrowseComponent implements OnInit {
    openLink = async () => {
        try {
          const url = ''

          if (await InAppBrowser.isAvailable()) {
            const result = await InAppBrowser.open(url, {
              // iOS Properties
              dismissButtonStyle: 'done',
              preferredBarTintColor: '#3e00be',
              preferredControlTintColor: 'white',
              readerMode: false,
              animated: true,
              modalPresentationStyle: 'fullScreen',
              modalTransitionStyle: 'crossDissolve',
              modalEnabled: true,
              enableBarCollapsing: false,
              // Android Properties
              showTitle: true,
              toolbarColor: '#3e00be',
              secondaryToolbarColor: 'white',
              enableUrlBarHiding: true,
              enableDefaultShare: true,
              forceCloseOnRedirection: false,
              // Specify full animation resource identifier(package:anim/name)
              // or only resource name(in case of animation bundled with app).
              animations: {
                startEnter: 'slide_in_right',
                startExit: 'slide_out_left',
                endEnter: 'slide_in_left',
                endExit: 'slide_out_right'
              },
              headers: {
                'my-custom-header': 'my custom header value'
              }
            })
            // alert({
            //   title: 'Response',
            //   message: JSON.stringify(result),
            //   okButtonText: 'Ok'
            // })
          }
          else {

            MyDelegate.prototype.applicationDidEnterBackground = function (application: UIApplication) {
              console.log('App is running in background');openUrl(url);
              AVAudioSession.sharedInstance().setCategoryWithOptionsError(
                  AVAudioSessionCategoryPlayAndRecord,
                  AVAudioSessionCategoryOptions.DefaultToSpeaker
              );
          };

          }
        }
        catch(error) {
          // alert({
          //   title: 'Error',
          //   message: error.message,
          //   okButtonText: 'Ok'
          // })
        }
      }

}

0 个答案:

没有答案
相关问题