cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Audio Auto Play

SOLVED
Alexandrite

Audio Auto Play

Hello,

 

I am looking for code to make the Audio start playing automatically upon the loading of a new view.

 

Avinash

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Audio Auto Play

Hello Avinash,

 

The solution is :

  1. In Resource, upload a wav file.
  2. In View, in 2D Canvas, add an Audio Widget
  3. In Properties, switch off these checkboxes : Show Controls and Visible
  4. In Preload list, select item Content 
  5. In .Js View, enter this code :
    $scope.$on('$ionicView.afterEnter', function(){
      // Anything you can think of
      twx.app.fn.triggerWidgetService('audio-1', 'play');
    })
    

When View will be finished to be loaded,  this event is triggered and we run Service Play of Audio Widget named audio-1.

 

Best regards,

Samuel

View solution in original post

Tags (1)
5 REPLIES 5
Highlighted

Re: Audio Auto Play

Hello Avinash,

 

The solution is :

  1. In Resource, upload a wav file.
  2. In View, in 2D Canvas, add an Audio Widget
  3. In Properties, switch off these checkboxes : Show Controls and Visible
  4. In Preload list, select item Content 
  5. In .Js View, enter this code :
    $scope.$on('$ionicView.afterEnter', function(){
      // Anything you can think of
      twx.app.fn.triggerWidgetService('audio-1', 'play');
    })
    

When View will be finished to be loaded,  this event is triggered and we run Service Play of Audio Widget named audio-1.

 

Best regards,

Samuel

View solution in original post

Tags (1)
Highlighted

Re: Audio Auto Play

how do we do this without an audio widget? 

Im building for the HOLO and they are not available...

 

im assuming something like theez?

any idea what im missing?

 

angular.element(document).ready(function () {
$scope.init();
});

 

$scope.init = function(){
MyMusic.mp3.play?();
};

 

Highlighted

Re: Audio Auto Play

Hello Justin,

 

In Hololens, the solution, I presume is :

 

In Javascript, add this code to play a sound file uploaded in Ressources.

Here, sound file will be played when opening Experience.

$scope.play = function () 
{
  var audio = new Audio('app/resources/Uploaded/166433__ultradust__concert-applause-2.wav');
  audio.play();
}

$scope.$on('$ionicView.afterEnter', function() {
  // Anything you can think of
  $scope.play ();
})

 

Source of information:

https://stackoverflow.com/questions/9419263/how-to-play-audio

 

I test it in Preview in my workstation and it works.

I don't have Hololens hardware to test on it and to confirm if it is working on device.

 

Please find attached this Project.

 

Best regards,

Samuel

Highlighted

Re: Audio Auto Play

How do I make sure it only plays in one view? Is there a way to contain it?
Highlighted

Re: Audio Auto Play

Hello Justin,

 

In example provided, JavaScript code is in the Home View in home.js.

It is played only when opening this View.

 

As in the example, this View is the only one and the one opened by default, it is played when opening Experience.

 

Best regards,

Samuel

Announcements
Join an
AR Working Group!

Topics available:
AR/VR for Data Optimization AR/VR for Security and Control AR/VR for Inspection