Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by loki-k-rasmussen · Jun 28, 2016 at 06:22 PM · networkingaudiophoton

Unity Audio Networking Stops Playing after 10s

Hello, I'm trying to get audio networking running in a multiplayer VR application I'm working on, which is currently using the Photon Cloud as a dedicated server, but is NOT using the Photon Voice Chat System (and I don't want it to, this has to do with the fact that I'm prototyping currently, but will be moving it to a dedicated server eventually.

My problem is: I Instantiate the Listener and Source along with the player, enabled with photonView.isMine (the photon checker for if the prefab belongs to the player) and everything runs perfectly with one person

even if their are two people everything is instantiated correctly and each AudioSource is playing its own clip from the player microphone and sending it as an RPC to all players, again everything instantiates correctly and runs perfectly but only for about ten seconds, then the Microphone on both players stops recording (or so it seems)

Once one player disconnects, eventually the Microphone begins to play correctly again.

My guess, is that it has something to do with the encoding or something stupid I don't know about RPC's (like that I should have one for each player) but I am at a loss.

Here is my code for the VoiceChat void Update() { // If there is a connection //Debug.Log(ready); if(ready == true){ if (photonView.isMine) { //Debug.Log("Connected for Audio"); int pos = Microphone.GetPosition(null); int diff = pos-lastSample;

                 if (diff > 0)
                 {
                     float[] samples = new float[diff * sendingClip.channels];
                     sendingClip.GetData (samples, lastSample);
                     byte[] ba = ToByteArray (samples);

                 PhotonNetwork.RPC (photonView, "Send", PhotonTargets.AllViaServer, false, ba, sendingClip.channels);

                     //Debug.Log(Microphone.GetPosition(null).ToString());
                 }
                 lastSample = pos;
             }

     
     }
 }
     
 [PunRPC]
 public void Send(byte[] ba, int chan) {
     float[] f = ToFloatArray(ba);
     if(audio != null){
         audio.clip = AudioClip.Create("" +photonView.ownerId, f.Length, chan, FREQUENCY,true,false);
         audio.clip.SetData(f, 0);
         Debug.Log(audio.isPlaying);
         if (!audio.isPlaying) audio.Play();
     }

 }
 // Used to convert the audio clip float array to bytes
 public byte[] ToByteArray(float[] floatArray) {
     int len = floatArray.Length * 4;
     byte[] byteArray = new byte[len];
     int pos = 0;
     foreach (float f in floatArray) {
         byte[] data = System.BitConverter.GetBytes(f);
         System.Array.Copy(data, 0, byteArray, pos, 4);
         pos += 4;
     }
     return byteArray;
 }
 // Used to convert the byte array to float array for the audio clip
 public float[] ToFloatArray(byte[] byteArray) {
     int len = byteArray.Length / 4;
     float[] floatArray = new float[len];
     for (int i = 0; i < byteArray.Length; i+=4) {
         floatArray[i/4] = System.BitConverter.ToSingle(byteArray, i);
     }
     return floatArray;
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

85 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Getting server browser with photon ? 3 Answers

Check what group id you have after being instantiated. (PUN) 1 Answer

Problem in Setting Photon Teams 2 Answers

Client Disconnect on Photon Server using MLAPI 0 Answers

Unity Photon doesn't Spawn Player 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges