2014-01-28 148 views
2

我目前在使用視頻播放器的Flex移動項目上苦苦掙扎。 基本上,問題是我似乎無法在iOS移動設備上播放或至少看到.MP4視頻(沒有視頻,沒有聲音,播放器視圖只是空的)。只要我用.FLV視頻替換視頻源,一切都可以正常工作。MP4視頻仍然隱藏在手機上Flex應用

我已經嘗試了兩種方法,即使他們使用了我所瞭解的下面的相同組件。

  • OSMF:使用VideoElement,MediaPlayer,MediaContainer和MediaPlayerSprite。

    private var media:VideoElement; 
        private var mediaPlayer:MediaPlayer; 
        private var mediaContainer:MediaContainer; 
        private var mediaSprite:MediaPlayerSprite; 
    
    
        protected function onViewCreationComplete(event:FlexEvent):void 
        { 
         media = new VideoElement(new URLResource("http://10.140.1.165/jobs/92/eproofing/in/pages/versions/1/page1/video.mp4")); 
         mediaPlayer = new MediaPlayer(media); 
         mediaContainer = new MediaContainer(); 
         mediaContainer.addMediaElement(media); 
         mediaSprite = new MediaPlayerSprite(mediaPlayer, mediaContainer); 
         mediaSprite.addEventListener(MouseEvent.CLICK, onVideoSpriteClicked, false, 0, true); 
         mediaSprite.mediaPlayer.addEventListener(TimeEvent.CURRENT_TIME_CHANGE, onVideoTimeChanged); 
    
         videoContainer.height = manager.selectedPage.formatHeight; 
         videoContainer.width = manager.selectedPage.formatWidth; 
         videoContainer.addChild(mediaSprite); 
        } 
    
  • 的StageVideo:使用視頻,NetConnection和NetStream(StageVideo對象使用其實並沒有在下面的代碼還沒有實現,這將是下一步)

    private var video:Video; 
        private var ns:NetStream; 
        private var nc:NetConnection; 
    
        private var isVideoPlaying:Boolean = false; 
    
    
        protected function onViewCreationComplete(event:FlexEvent):void 
        { 
         video = new Video(); 
         nc = new NetConnection(); 
         nc.connect(null); 
         ns = new NetStream(nc); 
         ns.client = {onMetaData:onMetaData}; 
    
         ns.addEventListener(NetStatusEvent.NET_STATUS, onVideoLoaded); 
         ns.play("http://10.140.1.165/jobs/92/eproofing/in/pages/versions/1/page1/video.mp4"); 
         this.isVideoPlaying = true; 
        } 
    
        private function onVideoLoaded(event:NetStatusEvent):void 
        { 
         video.attachNetStream(ns); 
         videoContainer.addChild(video); 
    
         videoContainer.height = video.height = video.videoHeight; 
         videoContainer.width = video.width = video.videoWidth; 
        } 
    
        private function onMetaData(o:Object):void 
        { 
    
        } 
    

兩個給我結果相同:只要我使用.FLV,視頻就會出現並且播放正確,只要我加載.MP4視頻,我就看不到/聽到任何東西 當然,MP4是我想要的格式o用於此項目。我可能會補充說我正在爲這些.MP4文件使用H.264編解碼器。

有什麼我做錯了嗎?

請注意,只要我使用模擬器,這兩種格式都可以使用,只有在我的iPad上部署應用程序時纔會發生.MP4問題。

這是移動的Flex 4.6項目,使用AIR 3.9Flash Builder的4.7的Windows 7專業版

回答

1

H.264視頻不支持與RTMP iOS設備,以及沒有使用HTTP Live Streaming協議,我沒有看到它的工作。下面是從NetStream.play的ActionScript參考一節:

在AIR 3.0 H.264視頻爲iOS

For H.264 video, the iOS APIs for video playback accept only a URL to a file or 
stream. You cannot pass in a buffer of H264 video data to be decoded. Depending 
on your video source, pass the appropriate argument to NetStream.play() as 
follows: 

- For progressive playback: Pass the URL of the file (local or remote). 

- For streaming video: Pass the URL of a playlist in Apple's HTTP Live Streaming 
(HLS) format. This file can be hosted by any server; Flash Media Server 4.5 and 
higher has the advantage of being able to encode streams in HLS format. 

+0

謝謝比爾。我不確定完全理解傳遞文件URL和視頻緩衝區之間的區別,但我肯定需要在這一點上做更多的研究。如果沒有其他答案,我會查看是否可以對此項目使用其他編碼。 –

+0

你有什麼解決方案?我有同樣的問題。 – ketan

+0

傳遞URL的格式相同,只是流式視頻需要HLS格式視頻(帶.m3u8後綴,流內容的播放列表文件)。很難遵循,但示例在https://developer.apple.com/streaming/上,其中一些可播放的流示例位於https://developer.apple.com/streaming/examples/basic-stream.html –

0

這並不容易,但如果你真的想在H264的特別注意事項RTMP在iOS上,您可以添加一個ANE來控制iOS RTMP視頻播放應用程序(本機)。有一些小公司爲iOS製作RTMP H264視頻播放器。