MPMoviePlayer sound working in Simulators and ipad device, but not Working in iPhone Device

こ雲淡風輕ζ 提交于 2019-12-24 05:01:45

问题


I have a problem with MPMoviePlayerController, i.e. I am playing the live stream url in (m3u8 format) MPMoviePlayer like below:

player = [[MPMoviePlayerController alloc] initWithContentURL:audioUrl];
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(loadStateDidChange:) 
                                                     name:MPMoviePlayerLoadStateDidChangeNotification 
                                                   object:player];
        if ([player respondsToSelector:@selector(loadState)]) 
        {
            // Set movie player layout

            [player setMovieSourceType:MPMovieSourceTypeStreaming];
            [player setControlStyle:MPMovieControlModeVolumeOnly];
            [player setFullscreen:YES];
            [player prepareToPlay];
            [player play];

        }
    }

It is working in both simulators & iPad device with ios 5 version, but it is not giving the audio in any iPhone device i have.

Please help me out... Thanks, in advance.


回答1:


mr simham ... check this below url it help for us becoZ

  1. Call stream-url within mobile safari. If that has the same results, then your code is correct and the stream is not. It would be an incorrectly encoded audio stream then.

  2. it depends on bandwidth also below ref url regards to bandwidth check it once.... u r ref Stream URL prepare,according to BandWith

REFERENCE URL:

  • http://wfmu.org/ssaudionet.shtml
  • APPLE



回答2:


You are assigning a deprecated MPMovieControlMode (MPMovieControlModeVolumeOnly) towards the controlStyle property which is expecting a MPMovieControlStyle.

Additionally, your code is missing the part that assigns the MPMoviePlayerController.view towards any superview and also its sizing is missing.

Last but I guess most importantly for you, I am guessing that the iPhone you are trying it with has set the volume all the way down to silence. Or, maybe the audio-routing is not set towards speaker-output. For the latter, make sure you are not setting up the audio session incorrectly anywhere else in your App. When in doubt, try fiddling with the useApplicationAudioSession property. Try setting it towards NO and see if that changes your results.

If all above fails, then one additional check would be to call the stream-url within mobile safari. If that has the same results, then your code is correct and the stream is not. It would be an incorrectly encoded audio stream then.




回答3:


Check if your iPhone is on loudspeaker mode or not -

if not than set it using this-

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);



回答4:


Check if the iPhone is in silent mode. To play audio even in silent mode, add the following code in AppDelegate's application:didFinishLaunchingWithOptions:

NSError *setCategoryErr = nil;
NSError *activationErr  = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];


来源:https://stackoverflow.com/questions/9408211/mpmovieplayer-sound-working-in-simulators-and-ipad-device-but-not-working-in-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!