iphone - ios media picker shows only white screen/stuck -
so i'm making music application project, , allows user create own music playlist. when clicked on show media picker button shows white screen, it doesn't happen when view contains media picker initial view controller. when come segue media picker view controller shows white screen if tapped button.
here code media picker view controller:
var mymusicplayer: mpmusicplayercontroller? override func viewdidload() { super.viewdidload() var buttonpickandplay = uibutton.buttonwithtype(.system) as? uibutton if let pickandplay = buttonpickandplay{ pickandplay.frame = cgrect(x: 0, y: 0, width: 200, height: 37) pickandplay.center = cgpoint(x: view.center.x, y: view.center.y - 50) pickandplay.settitle("pick , play", forstate: .normal) pickandplay.addtarget(self, action: "displaymediapickerandplayitem", forcontrolevents: .touchupinside) view.addsubview(pickandplay) } } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } func displaymediapickerandplayitem(){ var mediapicker = mpmediapickercontroller(mediatypes: .anyaudio) if let picker = mediapicker{ println("successfully instantiated media picker") picker.delegate = self picker.allowspickingmultipleitems = true picker.showsclouditems = true picker.prompt = "pick song please..." self.view.addsubview(picker.view) presentviewcontroller(picker, animated: true, completion: nil) } else { println("could not instantiate media picker") } } func mediapicker(mediapicker: mpmediapickercontroller!, didpickmediaitems mediaitemcollection: mpmediaitemcollection!){ println("media picker returned") /* instantiate music player */ mymusicplayer = mpmusicplayercontroller() if let player = mymusicplayer{ player.begingeneratingplaybacknotifications() /* notified when state of playback changes */ nsnotificationcenter.defaultcenter().addobserver(self, selector: "musicplayerstatechanged:", name: mpmusicplayercontrollerplaybackstatedidchangenotification, object: nil) /* notified when playback moves 1 item other. in recipe, going allow our user pick 1 music file */ nsnotificationcenter.defaultcenter().addobserver(self, selector: "nowplayingitemischanged:", name: mpmusicplayercontrollernowplayingitemdidchangenotification, object: nil) /* , notified when volume of music player changed */ nsnotificationcenter.defaultcenter().addobserver(self, selector: "volumeischanged:", name: mpmusicplayercontrollervolumedidchangenotification, object: nil) /* start playing items in collection */ player.setqueuewithitemcollection(mediaitemcollection) user.mdci = mediaitemcollection player.play() /* dismiss media picker controller */ mediapicker.dismissviewcontrolleranimated(true, completion: nil) } }
mpmediapickercontroller
uiviewcontroller
.
don't show in screen currentviewcontroller.view.addsubview(picker.view)
.
when show presentviewcontroller(picker, animated: true, completion: nil)
, it's correct way.
in delegate methods, when calling mediapicker.dismissviewcontrolleranimated(true, completion: nil)
, still had mediapicker.view
subview of currentviewcontroller.view
.
Comments
Post a Comment