最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Unity調(diào)取移動(dòng)端的麥克風(fēng)進(jìn)行錄音并播放

 更新時(shí)間:2020年04月16日 11:10:38   作者:幻世界  
這篇文章主要為大家詳細(xì)介紹了Unity調(diào)取移動(dòng)端的麥克風(fēng)進(jìn)行錄音并播放,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Unity調(diào)取移動(dòng)端的麥克風(fēng)進(jìn)行錄音并播放的具體代碼,供大家參考,具體內(nèi)容如下

1.對(duì)MicroPhone類的理解

對(duì)麥克風(fēng)的調(diào)用在Unity里主要是用到了MicroPhone這個(gè)類,此類里面有幾個(gè)方法可以方便我們實(shí)現(xiàn)功能

2.代碼演示

#region 模塊信息
// **********************************************************************
// Copyright (C) 2018 Blazors
// Please contact me if you have any questions
// File Name:  VoiceChat
// Author:  romantic123fly
// WeChat||QQ:  at853394528 || 853394528 
// **********************************************************************
#endregion
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
 
 
//此腳本須掛在錄音按鈕上
public class Record : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
 float tirecordingTimemer = 0;//錄音時(shí)長(zhǎng)限制
 public AudioSource aud;//存儲(chǔ)聲音
 public Text ShowTimeHint;//剩余時(shí)間的文字提示
 public void OnPointerDown(PointerEventData eventData)
 {
 Debug.Log("Start");
 StartCoroutine("KeepTime");
 aud.clip = Microphone.Start("Built-in Microphone", false, 60, 44100);
 }
 public void OnPointerUp(PointerEventData eventData)
 {
 Microphone.End("Built-in Microphone");
 StopCoroutine("KeepTime");
 Debug.Log("Over");
 aud.Play();
 }
 //此處開(kāi)攜程也行,用while也可以,放在updata里也沒(méi)問(wèn)題
 IEnumerator KeepTime()
 {
 for (tirecordingTimemer = 10; tirecordingTimemer >= 0; tirecordingTimemer -= Time.deltaTime)
 {
  if (tirecordingTimemer <= 10)
  {
  ShowTimeHint.text = "你還可以錄 " + (int)tirecordingTimemer + " 秒";
  if (tirecordingTimemer < 1)
  {
   ShowTimeHint.text = "時(shí)間到";
   Microphone.End("Built-in Microphone");
  }
  }
  yield return 0;
 }
 }
}

對(duì)應(yīng)的ui組件掛靠一下直接運(yùn)行工程就好了

3.運(yùn)行結(jié)果

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

永靖县| 黄大仙区| 合山市| 琼海市| 泗洪县| 巫溪县| 邹平县| 大同县| 西充县| 郴州市| 大庆市| 巴林右旗| 丹阳市| 东乌| 石狮市| 大石桥市| 迭部县| 丹巴县| 根河市| 临洮县| 栖霞市| 安仁县| 舟曲县| 安平县| 鄂尔多斯市| 望奎县| 九龙县| 叙永县| 博白县| 滦平县| 永寿县| 郁南县| 凤翔县| 郸城县| 商河县| 温泉县| 达孜县| 邹平县| 石门县| 页游| 武陟县|