在Android三星Galaxy S上播放流音频的问题

时间:2022-06-12 18:58:24

I just released my first Android app in my life. It's Audiko.

我刚刚发布了我的第一款Android应用程序。这是Audiko。

I found an error that occurs on Samsung Galaxy S during streaming mp3 file when I use the Android MediaPlayer.

我在使用Android MediaPlayer时发现在流媒体mp3文件中三星Galaxy S上发生了错误。

In logs I see this:

在日志中我看到:

E/PlayerDriver( 2747): PlayerDriver::it is a not Protected file

E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl
E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl
E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl
E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl
E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl
E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl
E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl
E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl
E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl
E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl
E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl
D/        ( 2747): PVFile::GetFileName
E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl
E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl
E/        ( 2747): IIIIIII Inside Constructor of PVMFMemoryBufferReadDataStreamImpl

V/PlayerDriver( 2747): Completed command PLAYER_INIT status=-1
E/PlayerDriver( 2747): Command PLAYER_INIT completed with an error or info -1
E/MediaPlayer(13523): error (1, -1)
E/MediaPlayer(13523): Error (1,-1)

Any suggestions on what it can be?

关于它可以是什么的任何建议?

2 个解决方案

#1


0  

I've had problems sort of like this on some devices. Your best bet is to just temporarily download the file and play that version instead of streaming it. That is, this would work if the ringtone is relatively small, which I would think is typically the case.

在某些设备上我遇到过类似的问题。您最好的选择是暂时下载文件并播放该版本而不是流式传输。也就是说,如果铃声相对较小,这将起作用,我认为通常就是这种情况。

#2


0  

I ran into something very similar. i use a Galaxy S2 for debugging and while trying to play a live radio stream i got all sort of errors and problems. First thing you have to know is that as some devices support the wma files (Windows Media Audio format) but the Galaxy doesn't so unless you find a way to convert that kind of stream to playable stream, you got a problem there.

我遇到了一些非常相似的东西。我使用Galaxy S2进行调试,在尝试播放实时广播流时,我遇到了各种错误和问题。首先要知道的是,由于某些设备支持wma文件(Windows Media Audio格式),但Galaxy并非如此,除非您找到将这种流转换为可播放流的方法,否则您会遇到问题。

The (kind of) solution i found for the problem is the following, as i read a long time ago somewhere what you can do is instead of using MediaPlayer and try to stream straight is to use an InputStream to read from the audio (right now i worked only with Mp3 because as i said wma wouldn't work) get a few seconds of audio into an mp3 file, and then use the MediaPlayer to play that file locally while Rebuffering the next part of the audio into a second file, and then just go back and forth playing those files ( you can set the length of each file )

我发现问题的(种类)解决方案如下,因为我很久以前在某处读过你可以做的不是使用MediaPlayer而是尝试直接流是使用InputStream来读取音频(现在我只使用Mp3,因为我说wma不起作用)将几秒音频输入mp3文件,然后使用MediaPlayer在本地播放该文件,同时将音频的下一部分重新缓冲到第二个文件中,然后只是来回播放这些文件(你可以设置每个文件的长度)

I leave you part of the code i was trying to implement and worked for buffering and playing the mp3 on my phone, but i didn't continue with the project has i haven't found a sutable solution for wma yet.

我留下你试图实现的代码的一部分,并在我的手机上缓冲和播放mp3,但我没有继续该项目,我还没有找到一个可靠的wma解决方案。

public void onClick(View v)
        {
            try
            {

                URL url = new URL("http://........./myStation.mp3");
                InputStream inputStream = url.openStream();
                long bytesRead = 0; 

                    File root = android.os.Environment.getExternalStorageDirectory();               
                    File dir = new File (root.getAbsolutePath() + "/usbStorage");
                    if(dir.exists()== false) 
                    {
                        dir.mkdirs();
                    }

                File outputSource = new File(dir, "test.mp3");
                FileOutputStream fileOutputStream = new FileOutputStream(outputSource);
                //Log.d(LOG_TAG, "FileOutputStream: " + outputSource);
                int c;
                int howManyBytes = 12000; 
            //You decide the amount of bytes to read because the live stream while keep on going forver
                while ((c = inputStream.read()) != 10000) 
                {

                    fileOutputStream.write(c);
                    bytesRead++;
                    if (bytesRead > howManyBytes) break;
                }
                fileOutputStream.close();
                MediaPlayer mp = MediaPlayer.create(this, Uri.fromFile(outputSource));
                mp.start(); // no need to call prepare(); create() does that for you
            }
            catch(Exception e)
            {
                Log.e("radio", e.getMessage());
            }
        }

#1


0  

I've had problems sort of like this on some devices. Your best bet is to just temporarily download the file and play that version instead of streaming it. That is, this would work if the ringtone is relatively small, which I would think is typically the case.

在某些设备上我遇到过类似的问题。您最好的选择是暂时下载文件并播放该版本而不是流式传输。也就是说,如果铃声相对较小,这将起作用,我认为通常就是这种情况。

#2


0  

I ran into something very similar. i use a Galaxy S2 for debugging and while trying to play a live radio stream i got all sort of errors and problems. First thing you have to know is that as some devices support the wma files (Windows Media Audio format) but the Galaxy doesn't so unless you find a way to convert that kind of stream to playable stream, you got a problem there.

我遇到了一些非常相似的东西。我使用Galaxy S2进行调试,在尝试播放实时广播流时,我遇到了各种错误和问题。首先要知道的是,由于某些设备支持wma文件(Windows Media Audio格式),但Galaxy并非如此,除非您找到将这种流转换为可播放流的方法,否则您会遇到问题。

The (kind of) solution i found for the problem is the following, as i read a long time ago somewhere what you can do is instead of using MediaPlayer and try to stream straight is to use an InputStream to read from the audio (right now i worked only with Mp3 because as i said wma wouldn't work) get a few seconds of audio into an mp3 file, and then use the MediaPlayer to play that file locally while Rebuffering the next part of the audio into a second file, and then just go back and forth playing those files ( you can set the length of each file )

我发现问题的(种类)解决方案如下,因为我很久以前在某处读过你可以做的不是使用MediaPlayer而是尝试直接流是使用InputStream来读取音频(现在我只使用Mp3,因为我说wma不起作用)将几秒音频输入mp3文件,然后使用MediaPlayer在本地播放该文件,同时将音频的下一部分重新缓冲到第二个文件中,然后只是来回播放这些文件(你可以设置每个文件的长度)

I leave you part of the code i was trying to implement and worked for buffering and playing the mp3 on my phone, but i didn't continue with the project has i haven't found a sutable solution for wma yet.

我留下你试图实现的代码的一部分,并在我的手机上缓冲和播放mp3,但我没有继续该项目,我还没有找到一个可靠的wma解决方案。

public void onClick(View v)
        {
            try
            {

                URL url = new URL("http://........./myStation.mp3");
                InputStream inputStream = url.openStream();
                long bytesRead = 0; 

                    File root = android.os.Environment.getExternalStorageDirectory();               
                    File dir = new File (root.getAbsolutePath() + "/usbStorage");
                    if(dir.exists()== false) 
                    {
                        dir.mkdirs();
                    }

                File outputSource = new File(dir, "test.mp3");
                FileOutputStream fileOutputStream = new FileOutputStream(outputSource);
                //Log.d(LOG_TAG, "FileOutputStream: " + outputSource);
                int c;
                int howManyBytes = 12000; 
            //You decide the amount of bytes to read because the live stream while keep on going forver
                while ((c = inputStream.read()) != 10000) 
                {

                    fileOutputStream.write(c);
                    bytesRead++;
                    if (bytesRead > howManyBytes) break;
                }
                fileOutputStream.close();
                MediaPlayer mp = MediaPlayer.create(this, Uri.fromFile(outputSource));
                mp.start(); // no need to call prepare(); create() does that for you
            }
            catch(Exception e)
            {
                Log.e("radio", e.getMessage());
            }
        }