MPMoviePlayer内存问题

时间:2016-11-11 12:31:17

标签: ios swift mpmovieplayercontroller mpmovieplayer

我正在升级我的视频应用程序,在这个应用程序中,我使用mpmovieplayer播放视频,所有功能都正常工作,但我有一个主要问题内存问题,

当我从服务器内存播放视频达到50 mb时,播放后的anthor视频内存增加50到70 MB。每次我播放新的视频内存都会增加。

我在viewdiddisapper中发布了mpmovieplayer对象,删除了观察者但没有工作任何

    func startplaying()
   {
    if a >= 0 && a <= videoID.count - 1
    {
        player = MPMoviePlayerController(contentURL: self.url)

        if defaults?.bool(forKey: "Rotation") == true
        {
          player?.view.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)
        }
        else
        {
             player?.view.frame = self.movieplayer.frame
        }

        self.img.isHidden = false
        defaults.set(videoTitle[a], forKey: "play_video")
        player?.scalingMode = MPMovieScalingMode.aspectFill
        player?.controlStyle = MPMovieControlStyle.none
        player?.movieSourceType = MPMovieSourceType.streaming
        player?.initialPlaybackTime = 0.0

        player?.initialPlaybackTime = 0.0
        defaults.set(false, forKey: "Shuffle")
        if  self.slid > 0.0
        {
          player?.currentPlaybackTime = TimeInterval(self.slid)
        }

        let origImage2 = UIImage(named: "play_normal");
        let tintedImage2 = origImage2?.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
        if self.a == 0 && self.pause.image(for: UIControlState()) == tintedImage2            {
            player?.pause()
        }
        else
        {
            if a == 0
            {
                player?.prepareToPlay()
            }
            else
            {
                player?.prepareToPlay()
            }
        }
        defaults?.removeObject(forKey: "bValue")
        defaults.set(a, forKey: "aValue")

        if self.url != nil
        {
         let asset = AVURLAsset(url: self.url!, options: nil)
         let genImg = AVAssetImageGenerator(asset: asset)
         genImg.appliesPreferredTrackTransform = true
         var time = asset.duration
         time.value = 50000
         do
         {
            try refImg = genImg.copyCGImage(at: time, actualTime: nil)
         }
         catch
         {

         }
        }

         timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(SimpleplayerViewController.updateTime), userInfo: nil, repeats: true)

        self.view.addSubview((player?.view)!)

         NotificationCenter.default.addObserver(self, selector: #selector(SimpleplayerViewController.RepeatSongs(_:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,object:player)
    }
}

任何人都可以给我正确的解决方案,我该如何解决这个问题。

0 个答案:

没有答案