查看: 2066|回复: 9
打印 上一主题 下一主题

流式音频预载入示例

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2011-11-25 15:32:00 |只看该作者 |倒序浏览


           流式音频预载入示例-Streaming audio in iPhone Unity (using obj-c) source code
         



           这个小教程是针对iphone进行开发,使用语言是obj-c,有项目源文件供下载!
         

           Isn’t it annoying that you have to pre-load your entire music track into memory before you can play it in Unity iPhone? When you have music files at 3meg or larger, it’s a huge amount of memory to use up when you are so limited.
         

           Since Unity iPhone doesn’t yet have streaming audio capability, I put something together to take care of it. Right now, it’s a pretty basic system .. but it plays, stops and pauses.
         

           For some reason, some people have reported a pulsing problem when the cpu is being heavily loaded – the game will stall a little. I don’t know that causes this, so if you solve it please do let me know so I can post the solution for everyone. Thanks!
         

           If you use this code and do anything cool with it, all I ask is that you share it with the Unity community.
         

            
         

           DOWNLOAD SOURCE HERE!
         

           To get going, you should just need a few lines in your AppController.mm file:
         

           1. Right at the top of your AppController.mm, add this line:
         

           #import “MusicController.h”
         

           2. Scroll down or use the search to find the function:
         

           - (void) applicationDidFinishLaunchingUIApplication*)application
         

           In that function, after the line:
         

           [self startUnity:application];
         

           Add this line:
         

           [[MusicController alloc] init];
         

           3. Scroll down or find the function:
         

           - (void) dealloc
         

           And within that function, before anything else happens there add the line:
         

           [MusicController dealloc];
         

           4. Add a reference to AVFoundation.framework … in xcode, go to the Project menu. Select ‘Add to Project’. Browse through the folders:
         

           SYSTEM -> Developer -> Platforms -> iPhoneOS.platform -> Developer -> SDKs -> iPhoneOS3.0.sdk -> System -> Library -> Frameworks
         

           Finally, once you made your way through all that, select AVFoundation.framework.
         

           5. Add calls to your game code in Unity:
         

           To play a track (NOTE: Right now this is set up to ONLY use mp3s. If you want to change this, search for mp3 in the MusicController.m file and change it to your chosen file format.)
         

           PlayerPrefs.SetString(“
           


            _
           
           music
           
            _
           
           filename”, );
         

           theFilename is your audio file name (with no extension) and this one pref will start the music playing.
         

           IMPORTANT: Don’t include the file extension in your filename here, just the filename alone. The obj-c will add the .mp3 for you. Also, do not include a path. Just the filename is enough, as it all gets flattened down when you build.
         

           I put all my audio in a folder called ‘MP3′ in the root of my xcode project, so feel free to place them in a subfolder, but don’t forget to add the music files to your project by going to the Project menu / Add to Project and select your folder of audio files.
         

           To stop the track:
         

           PlayerPrefs.SetInt(“
           
            _
           
           stop
           
            _
           
           music”,1);
         

           To pause the track:
         

           PlayerPrefs.SetInt(“
           
            _
           
           pause
           
            _
           
           music”,1);
         

           To play after a pause:
         

           PlayerPrefs.SetInt(“
           
            _
           
           play
           
            _
           
           music”,1);
         

           One more thing … search MusicController.m for ‘AVAudioSessionCategoryPlayback’ to change the way the audio player works. There are a few different methods. The following list is taken from the Apple developer site. It’s up to you to pick the right one to suit your application
         

           AVAudioSessionCategoryAmbient
           

           For an application in which sound playback is nonprimary—your application can be used successfully with the sound turned off. This category is also appropriate for “play along” style applications, such as a virtual piano that a user plays over iPod audio. When you use this category, other audio, such as from the iPod application, mixes with your audio. Your audio is silenced by screen locking and by the Ring/Silent switch.
           

           Available in iPhone OS 3.0 and later.
         

           Declared in
           

           AVAudioSession.h
           

           .
         



           AVAudioSessionCategorySoloAmbient
           

           The default category; used unless you set a category with the
           

           setCategory:error:
           

            method. This category silences audio from other applications, such as the iPod. Your audio is silenced by screen locking and by the Ring/Silent switch.
           

           Available in iPhone OS 3.0 and later.
         

           Declared in
           

           AVAudioSession.h
           

           .
         



           AVAudioSessionCategoryPlayback
           

           For playing recorded music or other sounds that are central to the successful use of your application. This category silences audio from other applications, such as the iPod. You can, however, modify this category to allow mixing by using the
           

           kAudioSessionProperty
           
            _
           
           OverrideCategoryMixWithOthers
           

            property. Your audio continues with the Ring/Silent switch set to silent and with the screen locked.
           

           Available in iPhone OS 3.0 and later.
         

           Declared in
           

           AVAudioSession.h
           

           .
         



           AVAudioSessionCategoryRecord
           

           For recording audio; this category silences playback audio. Recording continues with the screen locked.
           

           Available in iPhone OS 3.0 and later.
         

           Declared in
           

           AVAudioSession.h
           

           .
         



           AVAudioSessionCategoryPlayAndRecord
           

           For recording and playback of audio—simultaneous or not—such as for a VOIP (voice over IP) application. This category silences audio from other applications, such as the iPod. You can, however, modify this category to allow mixing by using the
           

           kAudioSessionProperty
           
            _
           
           OverrideCategoryMixWithOthers
           

            property. Your audio continues with the Ring/Silent switch set to silent and with the screen locked.
           

           Available in iPhone OS 3.0 and later.
         

           Declared in
           

           AVAudioSession.h
           

           .
         



           AVAudioSessionCategoryAudioProcessing
           

           For using an audio hardware codec or signal processor while not playing or recording audio. Use this category, for example, when performing offline audio format conversion.
           

           Available in iPhone OS 3.1 and later.
         

           Declared in
           

           AVAudioSession.h
           

           .
         

           Annnd I think that’s everything.
         

           Good luck!
         

           转自:http://psychicparrotgames.com/?p=33
         
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2012-1-30 23:24:04 |只看该作者
新雪时舞蹈, 年夜思悄然。
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

板凳
发表于 2012-2-26 23:18:25 |只看该作者
跑着去顶朋友滴铁
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

地板
发表于 2012-4-2 23:23:46 |只看该作者
跑着去顶朋友滴铁
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

5#
发表于 2012-5-29 23:27:01 |只看该作者
有意思!学习了!
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

6#
发表于 2012-7-23 23:19:05 |只看该作者
百度的叫度娘,网易的叫易娘,新浪内部还在为是叫新娘还是浪娘而争论不休!……不管你们是企鹅的额娘,豆瓣的伴娘,还是华为的伪娘,都要记得,淘宝才是你们的亲娘啊!亲!!
回复

使用道具 举报

3795

主题

2

听众

5万

积分

版主

Rank: 7Rank: 7Rank: 7

纳金币
53202
精华
32

活跃会员 优秀版主 推广达人 突出贡献 荣誉管理 论坛元老

7#
发表于 2012-7-24 09:31:28 |只看该作者
http://www.edy.es/unity/Offroader.html/
回复

使用道具 举报

3795

主题

2

听众

5万

积分

版主

Rank: 7Rank: 7Rank: 7

纳金币
53202
精华
32

活跃会员 优秀版主 推广达人 突出贡献 荣誉管理 论坛元老

8#
发表于 2012-7-24 09:32:32 |只看该作者
高手速来赐教!kismet里面怎么加一个延迟DELAY??



unity特效大家PP_武功盖世呀








【严重分享】Unity3D_3.0破解版[安装包][下载]






高手请赐教!用模型做的特效动画材质丢失








antares_universe(vizio)可视化编辑
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

9#
发表于 2013-1-28 23:25:16 |只看该作者
不会吧,太恐怖了
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

10#
发表于 2013-2-24 23:22:41 |只看该作者
都闪开,介个帖子,偶来顶
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-7-28 13:39 , Processed in 0.109542 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部