ios - Autoplay MPMoviePlayerController when video scrolls into view -
i making ios app feed people can post videos , videos show on feed similar instagrams. want have videos seen start autoplaying , have 1 video play @ time. having problems in ios simulator more 1 video play @ time , of videos aren't seen in screen.
here code:
import uikit import parse import parseui import mediaplayer import mobilecoreservices class userstableviewcontroller: pfquerytableviewcontroller { let cellidentifier:string = "usercell" var objmovieplayercontroller: mpmovieplayercontroller = mpmovieplayercontroller() override func viewdidload() { super.viewdidload() self.pulltorefreshenabled = true self.paginationenabled = false self.objectsperpage = 25 self.tableview.rowheight = 422 self.tableview.allowsselection = false let font = uifont(name: "apple sd gothic neo", size: 24.0) ?? uifont.systemfontofsize(24) var nav = self.navigationcontroller?.navigationbar nav?.barstyle = uibarstyle.default nav?.bartintcolor = uicolor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) nav?.titletextattributes = [nsfontattributename : font, nsforegroundcolorattributename : uicolor(red: 1.0, green: (203.0/255.0), blue: (38.0/255.0), alpha: 1.0)] } override func viewwillappear(animated: bool) { self.navigationitem.hidesbackbutton = true } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } override func queryfortable() -> pfquery { var query : pfquery = pfuser.query()! var currentuser = pfuser.currentuser()! let currentusergender : string = currentuser["gender"] as! string let acceptablegenderprefs = ["both", currentusergender] let currentusergenderpref : string = currentuser["genderpref"] as! string query.wherekey("username", notequalto: currentuser.username!) query.wherekey("genderpref", containedin: acceptablegenderprefs) if (currentusergenderpref != "both") { query.wherekey("gender", equalto: currentusergenderpref) } return query } override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath, object: pfobject?) -> pftableviewcell? { var cell : userstableviewcell? = tableview.dequeuereusablecellwithidentifier(cellidentifier, forindexpath: indexpath) as? userstableviewcell if(cell == nil) { cell = userstableviewcell(style: uitableviewcellstyle.value1, reuseidentifier: cellidentifier) } if let pfobject = object { cell?.usernamelabel?.text = pfobject["username"] as? string var profilepic = pfobject["profilepicture"] as? pffile var video1 = pfobject["video1"] as? pffile profilepic?.getdatainbackgroundwithblock({ (result, error) in if (result != nil) { cell?.userprofilepicture?.image = uiimage(data: result!) } }) let video1url = nsurl(string: (video1?.url)!) objmovieplayercontroller = mpmovieplayercontroller(contenturl: video1url) objmovieplayercontroller.moviesourcetype = mpmoviesourcetype.unknown objmovieplayercontroller.view.frame = (cell?.uservideo1.bounds)! objmovieplayercontroller.scalingmode = mpmoviescalingmode.aspectfit objmovieplayercontroller.controlstyle = mpmoviecontrolstyle.none objmovieplayercontroller.repeatmode = mpmovierepeatmode.one objmovieplayercontroller.shouldautoplay = true cell?.uservideo1.addsubview(objmovieplayercontroller.view) objmovieplayercontroller.preparetoplay() objmovieplayercontroller.play() } return cell } // mark: actions @ibaction func signoutaction(sender: anyobject) { pfuser.logout() self.navigationcontroller?.poptorootviewcontrolleranimated(false) } }
thank you help!
probably better way be
- don't play until scrolling comes halt
- verify if cell visible (at least 3/4th of height in visible area)
- even if want play while scrolling fast, set audio mute default. provide clickable icon on top of video enable/disable audio too
these observations on how instagram might doing.
Comments
Post a Comment