MPmovieplayercontroller audio issue

199 views Asked by At

I am creating simple media player my problem is when i click on next button then video change but sound of previous video is coming 3 - 4 seconds in new video then after sound change

here is my code

Play video code

func startplaying()
{
  if a >= 0 && a <= arr.count - 1
  {
    println(a)
    filesArray  = NSFileManager.defaultManager().contentsOfDirectoryAtPath(fileDestination, error: nil)!
    var predicate = NSPredicate(format: "self ENDSWITH '.mp4'", filesArray)
    filesArray = filesArray.filteredArrayUsingPredicate(predicate)
    videoPath = fileDestination.stringByAppendingPathComponent(arr[a])
    videoPath = "file://".stringByAppendingPathComponent(videoPath)
    println(arr[a])
    videoPath = Utilities.Instance().urlEncoder(videoPath)

    let url =  NSURL(string: videoPath)

    movieplayer = MPMoviePlayerController(contentURL: url)
    // navigationItem.title = name
    titleLabel.text = arr[a]
    navigationItem.hidesBackButton = true
    movieplayer.view.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)
    movieplayer.view.sizeToFit()
    movieplayer.fullscreen = true
    movieplayer.scalingMode = MPMovieScalingMode.AspectFit
    movieplayer.fullscreen = true
    movieplayer.controlStyle = MPMovieControlStyle.None
    movieplayer.movieSourceType = MPMovieSourceType.File
    movieplayer.play()
    slider.value = 0
    slider.maximumValue = Float(movieplayer.duration)
    timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "updateTime", userInfo: nil, repeats: true)
    self.view.addSubview(movieplayer.view)
    self.view.addSubview(butView)
    self.view.addSubview(titleView)
   }
}

Next button code

if a <= arr.count - 1 || play.titleLabel == "Play"
{
   a++
   startplaying()
   play.setImage(UIImage(named: "Pause-50.png"), forState: UIControlState.Normal)
   if a > arr.count - 1
     {
      a = 0
      startplaying()
      movieplayer.pause()
      play.setImage(UIImage(named: "Play-50.png"), forState: UIControlState.Normal)
      flag = 1
     }
 }
0

There are 0 answers