Search Unity

Media Player with Audio Clip?

Discussion in 'Scripting' started by longbottomup, Apr 8, 2015.

  1. longbottomup

    longbottomup

    Joined:
    Nov 2, 2013
    Posts:
    49
    I want to make a simple Media Player app play mp3 file. I can play mp3 with Audio Clip on Unity? Or something else? Because when i compare the mp3 on Unity with an app on App Store, i see there is one small difference, seem App Store' sounds better, good. Someone can tell me little of basic knowledge for Media Player App? Thank you.
     
  2. Eths

    Eths

    Joined:
    Mar 5, 2015
    Posts:
    184
    First you need to Create an Audio source on unity and uncheck Play on Awake if you don't want it to play when you start the game and then make a script for example, Example.cs

    inside the Example.cs you need to make a public AudioSource, and public AudioClip
    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4.        
    5. using System.Collections;
    6.  
    7.  
    8.  
    9. public class Example : MonoBehaviour
    10. {
    11.        public AudioSource TestSource;
    12.        public AudioClip TestClip;
    13.        //When the game starts it will stop the audio just incase the audio is running
    14.        void Awake(){
    15.         TestSource.stop();
    16.         }      
    17.        //When the script is started it will Change the Clip of the audio source to testclip then play it.
    18.        void Start(){
    19.       //Change TestSource's clip to TestClip
    20.         TestSource.clip = TestClip;
    21.      // Play the Audio
    22.        TestSource.play();
    23.         }
    24. }
    25.  
    26.  
    you need to create an empty game object and attach that script to it.
    Then you will see TestSource and TestClip variable,
    Put the audio source you created on TestSource.
    and The .mp3 file on TestClip then you are done :)
     
    longbottomup likes this.
  3. longbottomup

    longbottomup

    Joined:
    Nov 2, 2013
    Posts:
    49
    Thank for your help. But, the question here: the sound play on Audio Clip is the best?
     
    Eths likes this.
  4. Eths

    Eths

    Joined:
    Mar 5, 2015
    Posts:
    184
    Yes for sure! I have used it in a lot of projects and it's just working awesome and very easy to use!
     
    longbottomup likes this.
  5. longbottomup

    longbottomup

    Joined:
    Nov 2, 2013
    Posts:
    49
    Thank pro, so, how about flac? Can you tell me "keyword" to play it on Unity App?