本文介绍了同步在Android上多音轨的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个基于音乐游戏(类似我唱的怪物)的想法是,我有一个场景,我可以把从场景中删除了几个不同的角色,每个角色都有独特的MP3文件为其唱歌。

I'm trying to create a music based game (similar to "my singing monsters). the idea is that I have a scene where I can place and remove a few different characters from the scene, each character has a unique mp3 file for its singing.

我建设我的游戏cocos2dx尽管对于声音我使用它目前使用的MediaPlayer API在Android定制的引擎。为了所有的声音一起同步我只是发挥他们所有当场景被载入,然后只是静音和取消静音根据这些字符是在现场。问题是,旧设备上的声音似乎是不同步的,我认为我需要一种方法来pre-缓存加载的mp3文件之前。

I'm building my game with cocos2dx though for sounds I'm using a custom engine which currently uses MediaPlayer API on android. In order to sync all the sounds together I just play them all when the scene is loaded and then just mute and unmute according to which character is on scene. the problem is that on older devices the sounds seems to be out of sync, I assume that I need a way to pre-cache the mp3 files before they are loaded.

我试着在先进创建所有mediaPlayers并使用prepare()方法,然后将它们保存在一个HashMap,只是使用播放()当场景开始打他们。遗憾的是它没有工作,轨道仍然是不同步的。我不知道怎么MediaPlayer的工作,所以我不知道,如果想在先进创建它相当于pre-缓存。标准cocos2dx听起来发动机采用的Soundpool我的理解是不适合大文件,我不知道它是否有缓存机制。 iOS上的我已经有一个使用OpenAL的一个声音引擎和iPad上的4我测试了它工作得很好。

I tried creating all the mediaPlayers in advanced and use the prepare() method, then save them in a hashmap and just use play() when the scene is started to play them all. unfortunately it didn't work and the tracks are still out of sync. I'm not sure how MediaPlayer work so I don't know if trying to create it in advanced is equivalent to pre-caching. The standard cocos2dx sounds engine uses soundpool which I understand is not good for large files and I'm not sure if it has a caching mechanism. On Ios I already had a sounds engine that uses openAL and on the ipad 4 I tested it works just fine.

你有什么建议我为了同步轨道呢?实现另一个声音引擎?也许基于openSL?或以某种方式保持一个定时器,并用它来同步轨道。

What do you suggest I do in order to sync the tracks? implement another sounds engine? maybe based on openSL? or somehow keep a timer and use it to sync tracks.

如何将设计的声音这样一个游戏,它让所有的轨道同步在一起最重要的事情?

How would design the sound for such a game where it is the most important thing to have all the tracks synced together?

推荐答案

的问题是,每个MediaPlayer的重新presents一个单独的流,其可以在不同的时间启动。即使你在打电话的同时启动所有的(这是不可能的),有没有办法保证该操作系统将加载并真正开始每个人在同一时间。

The problem is that each MediaPlayer represents a separate stream, which may start at different times. Even if you call start on all of them at the same time (which is impossible), there's no way to guarantee that the OS will load and actually start each one at the same time.

据我所知,Android提供了没有办法多个数据流同步。即使操作系统那些提供这种能力,这是非常繁琐的,而且通常不是100%准确。

As far as I know, Android offers no way to synchronize multiple streams. Even with operating systems that do offer this capability, it's extremely cumbersome, and usually not 100% accurate.

正确的解决办法是使用接口,并执行MP3解码,并将数据发送到流之前混合自己。

The correct solution is to open a single stream, eg using the audio track interface, and do the MP3 decoding and mixing yourself before sending the data to the stream.

这篇关于同步在Android上多音轨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 04:58