媒体播放器的两个对象不能同时播放同步中的歌曲 [英] Two Object of media Player not play song in Sync at same time

查看:91
本文介绍了媒体播放器的两个对象不能同时播放同步中的歌曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个android应用程序.此应用程序的正常概念是在同一时间在多个设备中播放歌曲.一切都已完成,但歌曲无法在Sync中播放.我已经做了很多研发工作来解决此问题问题,但没有成功.但是最后我找到了一个Android Media Player发行版.为找到这个问题,我制作了一个演示应用程序.说明如下.

I have working on to one android application.Normal concept of this application is to Play Song in Multiple Device at Same Time.Everything is done but Song is not play in Sync.I have done lot's of R&d to solve this problem but not getting success.but at end I have found one Issue of Android Media Player.For finding this issue I have making one demo Application.Description is follow.

演示应用说明

我创建了一个Android媒体播放器的两个对象firstPlayer和secondPlayer.一旦应用程序是Lunch,将开始播放歌曲.现在我在test.xml中单击了一个按钮.一旦用户单击此按钮,secondPlayer将开始并播放我在firstPlayer中设置的相同音乐.我也在firstPlayer为Play的位置上寻找secondPlayer.

I create a two object of Android media player firstPlayer and secondPlayer.firstPlayer Song playing will be start once App is Lunch.now i have taking one Button in test.xml.once the User will click in this button secondPlayer is start and play same music which I set in firstPlayer.and I also Seek secondPlayer at Position where firstPlayer is Play.

代码

  changePlayer = (Button) findViewById(R.id.changePlayer);


    String fileName = "/qq.mp3";
    String baseDir = Environment.getExternalStorageDirectory() + "/Test App" + fileName;

    Log.e(TAG, "path :" + baseDir);
    try {
        firstPlayer = new MediaPlayer();
        secondPlayer = new MediaPlayer();

        firstPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        secondPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

        firstPlayer.setDataSource(baseDir);
        secondPlayer.setDataSource(baseDir);

        firstPlayer.prepare();
        secondPlayer.prepare();

        firstPlayer.start();


    } catch (IOException e) {
        e.printStackTrace();
    }


    changePlayer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!secondPlayer.isPlaying()) {
                Log.e(TAG, "Media Player Start M2");
                secondPlayer.start();
            }
            int sek = firstPlayer.getCurrentPosition();
            secondPlayer.seekTo(firstPlayer.getCurrentPosition());
            //firstPlayer.seekTo(sek);

            Log.e(TAG, "Current Playe Time ::" + secondPlayer.getCurrentPosition());
            Log.e(TAG, "First Playe Time ::" + sek);
            Log.e(TAG, "firstPlayer Playe Time ::" + firstPlayer.getCurrentPosition());
            Log.e(TAG, "secondPlayer Playe Time ::" + secondPlayer.getCurrentPosition());

        }
    });

问题

  • 我遇到一个奇怪的问题,两个媒体播放器均未在Sync中播放,播放歌曲有一点点不同.如果我在secondPlayer中播放firstPlayer,则它正在Sync中播放,但两个播放器均未播放不同.

注意

  • 我也尝试使用任何第三方媒体播放器解决此问题,但是我没有走运.我已经实现了ExoPlayer,VlcPlayer,UniversalPlayer来解决此问题,但是它也有相同的问题.

要求.

  • 我想在MediaPlayer的两个不同对象中以同步方式播放歌曲.
  • 没有人知道没有此延迟问题的强大的媒体播放器.

我几乎没有尝试解决这个同步问题,但是我没有得到运气.我想在我的应用程序中实现100%同步.就像IOS中的Seedio应用程序一样.我也在IOS中对其进行了测试,但在IOS中它可以正常工作歌曲具有100%同步.

I hardly Try to solve this Sync issue but i Didn't get Luck.I want 100% Sync in My Application.Just Like Seedio app in IOS.I also test this in IOS but in IOS it's Working fine Both Player play song with 100% sync.

如果有人有任何想法,请帮助我.

Please Help me if Anyone have any Idea.

希望大家都清楚我的问题.

I hope you all are clear with my problem.

谢谢

推荐答案

Seek确实需要在MediaPlayer上花费一些时间.(据我了解,官方文档: https://developer.android.com/reference/android/media/MediaPlayer )

The Seek does take some time on a MediaPlayer. (As I understand the official docs: https://developer.android.com/reference/android/media/MediaPlayer)

一个想法是使第二流不开始,寻找到已知的未来位置(高于第一流的当前位置),希望它及时"到达那里.然后,到达那里时(时间已经过去),开始第二个视频流.我还没有测试过它,只是想着要解决一个非常相似的问题.

One idea is to have the second stream not started, seek to a known future position (higher than currect pos of first stream), hope it gets there "in time". And then start the second stream when you get there (time has passed). I have not tested it, just been thinking about it as I want to solve a very similar issue.

这篇关于媒体播放器的两个对象不能同时播放同步中的歌曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆