DEN
DEN

Reputation: 1893

Ionic Cordova native touch sound

I am newbie in hybrid app development using ionic 1 with angularJs. I have deployed the app to my samsung device (android). I found out that when I touch any elements (eg: button) it doesn't have any sounds effect.

How to enable the touch sound like the native app?

I also visited this article http://gonehybrid.com/how-to-add-sound-effects-to-your-ionic-app-with-native-audio/ , but this is not I want to achieve. It teach on how to enable and load audio in the app. However, I want to have the native touch sound of the phone

I apologize if this similar question exist in somewhere else, I have searched through a lot of sites and I couldn't find an answer

I also tried https://github.com/MatiMenich/cordova-plugin-nativeClickSound and no luck.. Please find the code below for my index.html and controller.js

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link rel="manifest" href="manifest.json">

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="lib/ionic/js/angular/angular-resource.min.js"></script>
    <script src="lib/ngCordova/dist/ng-cordova.js"></script> 

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>
    <script src="js/services.js"></script>
  </head>
  <body ng-app="starter">

    <ion-nav-bar class="bar-stable">
      <ion-nav-back-button>
      </ion-nav-back-button>

    </ion-nav-bar>

    <ion-nav-view></ion-nav-view>
  </body>
</html>


<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link rel="manifest" href="manifest.json">

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="lib/ionic/js/angular/angular-resource.min.js"></script>
    <script src="lib/ngCordova/dist/ng-cordova.js"></script> 

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>
    <script src="js/services.js"></script>
  </head>
  <body ng-app="starter">

    <ion-nav-bar class="bar-stable">
      <ion-nav-back-button>
      </ion-nav-back-button>

    </ion-nav-bar>

    <ion-nav-view></ion-nav-view>
  </body>
</html>

controller.js

.controller('SoundController', function($ionicPlatform, $scope, $timeout){
    var clickyClasses = ['sound-click', 'button']; 
    nativeclick.watch(clickyClasses);
    $scope.click = function() {
      nativeclick.trigger();
    };
})

Upvotes: 0

Views: 1365

Answers (2)

raj peer
raj peer

Reputation: 718

install plugin 'cordova plugin add cordova-plugin-nativeclicksound'

use this code in app.js

.controller('MyController',function($scope,
$cordovaNativeAudio) {   

    $scope.sound = function() {
            nativeclick.trigger();
     };
});

you can use sound() function where ever you want native sound, for example button

<button ng-click="sound()">native sound</button> 

test it in device, web browser through error.

Upvotes: 1

digit
digit

Reputation: 4565

You can try https://github.com/MatiMenich/cordova-plugin-nativeClickSound. It's under MIT License. Hope it'll help you

This will applied native sound to all button and an "a" tag with href when clicking it.

var clickyClasses = ['button', 'a']; 
nativeclick.watch(clickyClasses);

Upvotes: 1

Related Questions