MPMediaQuery.songsQuery().items returns nil - mpmediaquery

first time I am touching Mediaquery and I am stucked.
I have the following lines in xcode
import MediaPlayer
class ViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
let mediaItems = MPMediaQuery.songsQuery().items
But media items is always empty / nil.
Any idea what I missed?
Ok I found the reason, this is very time consuming to find such information.
Simulator:
Unsupported frameworks include:
External Accessory
Media Player
Rpw

Have you imported the MediaPlayer framework?
try this
import MediaPlayer
class CLASSNAME {
override func viewDidLoad() {
let allTracks: NSArray = MPMediaQuery.songsQuery().items as NSArray
println("All tracks: \(allTracks)")
}
}

Related

I am trying to edit a thought in my thoughts app. I am not able to update it

package com.example.demo
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.firestore.FirebaseFirestore
import kotlinx.android.synthetic.main.activity_update_thought.*
class UpdateThoughtActivity : AppCompatActivity() {
private lateinit var thoughtDocumentId: String
lateinit var commentDocId: String
lateinit var thoughtTxt: String
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_update_thought)
thoughtDocumentId = intent.getStringExtra(THOUGHT_DOC_ID_EXTRA)!!
commentDocId = intent.getStringExtra(COMMENT_USER_ID_EXTRA)!!
thoughtTxt = intent.getStringExtra(COMMENT_TXT_EXTRA)!!
updateThoughtTxt.setText(thoughtTxt)
}
fun updateThoughtClicked(view: View) {
FirebaseFirestore.getInstance().collection(THOUGHTS_REF).document(thoughtDocumentId)
.update(THOUGHT_TXT, updateThoughtTxt.text.toString())
.addOnSuccessListener {
hideKeyboard()
finish()
}
.addOnFailureListener { exception ->
Log.e("Exception", "Could not update thought: ${exception.localizedMessage}")
}
}
private fun hideKeyboard() {
val inputManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
if (inputManager.isAcceptingText) {
inputManager.hideSoftInputFromWindow(currentFocus!!.windowToken,0)
}
}
}
Here I am trying to update the thought. I am not able to update it.When I click on update button during runtime. I see this error.
E Could not update thought: NOT_FOUND: No document to update: projects/fir-ee876/databases/(default)/documents/thoughts/null
I did for comments activity the same thing. It works fine. I am getting problem only for this.
Can you please help me with this?
I am trying to edit the thought and when I click on edit option it navigates to a new activity. In the new activity I want to update the thought and click on update button.When I click on that button the thought must be updated and must be displayed. When I tried this I am getting this error.
E Could not update thought: NOT_FOUND: No document to update: projects/fir-ee876/databases/(default)/documents/thoughts/null

button click inside an item in recyclerview refreshes entire activity

I'm implementing a RecyclerView which has items which have a delete button, the data comes from Firebase and the delete button changes a "saved" value in firebase. this recyclerview is present in the third menu of the bottom navigation bar of the main activity.
When I click on the delete button, the entire activity restarts and the activity starts with the first menu of the bottom navigation bar
How do I stop this restarting action?
I'm attaching the RecyclerView adapter code below:
package com.demo.ash.demoapp
import android.content.Intent
import android.os.Environment
import android.support.v7.widget.RecyclerView
import android.transition.TransitionManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.database.FirebaseDatabase
import kotlinx.android.synthetic.main.offline_client.view.*
import kotlinx.android.synthetic.main.activity_main.*
import org.json.JSONObject
import java.io.File
/**
* Created by ashwin on 3/5/2018.
*/
class OfflineClientAdapter(val list: MutableList<Client>, val clientIDList:MutableList<String>): RecyclerView.Adapter<OfflineClientViewHolder>() {
lateinit var vg: ViewGroup
override fun getItemCount(): Int {
return list.size
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): OfflineClientViewHolder {
val layoutInflator = LayoutInflater.from(parent?.context)
vg = parent!!
val cellForRow = layoutInflator.inflate(R.layout.offline_client, parent, false)
return OfflineClientViewHolder(cellForRow, "")
}
override fun onBindViewHolder(holder: OfflineClientViewHolder?, position: Int) {
val row = list.get(position)
holder?.view?.NameView?.text = row.cname
holder?.view?.PhnumView?.text = row.cphonenum
holder?.clientID = clientIDList[position]
var encodedimage = IOHelper.stringToBitmap(row.cimage)
holder?.view?.client_image?.setImageBitmap(encodedimage)
val user = FirebaseAuth.getInstance().currentUser
var database = FirebaseDatabase.getInstance().getReference("Users").child(user?.phoneNumber)
.child("Clients").child(clientIDList[position])
holder?.view?.delete_client?.setOnClickListener {
val path = Environment.getExternalStorageDirectory()
val dir = File(path.toString() + "/pranjal/saved_clients.txt")
var clients = IOHelper.stringFromFile(dir)
var t = JSONObject(clients)
t.remove(clientIDList[position])
database.child("saved").setValue(false)
}
}
}
class OfflineClientViewHolder(val view: View, var clientID: String): RecyclerView.ViewHolder(view) {
init{
view.setOnClickListener {
val intent = Intent(view.context, OfflinePatientListActivity::class.java)
intent.putExtra("clientID",clientID)
view.context.startActivity(intent)
}
}
}
If you don't want to start an activity on button click, why do you have this code?
view.context.startActivity(intent)
?
When I click on the delete button, the entire activity restarts and the activity starts with the first menu of the bottom navigation bar
It kinda sounds like your Application is crashing. Unless you are doing something that would unintentionally (or intentionally?) restart said Activity.
It looks like you are changing the adapters data (deleting it) without calling the necessary methods to alert the adapter and recylerview that it needs to update its data. Make sure you call the necessary .notify...() methods after updating the data.
If the delete button is a part of the recylerview, make sure that you are taking it into account in the appropriate callbacks / code.
I’d make sure there aren’t any crashes going on in your
.delete_client?.setOnClickListener { ... }code.
Also make sure you aren’t accessing a null list in the other callbacks.
Hope this helps!

Main.Storyboard is not loaded correctly after implementing a new rootController

I have an issue, which hasn't been fixed by now. Since I have added a feature, so that the app starts by showing the loginviewController when the user is not logged in or going directly to the userViewcontroller which represents the app functions, everything which is created in the Storyboard is not visible and the app just shows a black screen.
I am working with Firebase. I have recently added the Facebook Button, which works perfectly fine. Since it was created without the Storyboard it is the only object to be shown in the app. After the user logs in with the Facebook button, it shows a black screen again.
I have added the following code to the app delegate:
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = MainViewController()
The MainController has the following code:
import UIKit
class MainViewController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red
let isLoggedIn = false
if isLoggedIn {
}else {
perform(#selector(showLoginController), with: nil, afterDelay: 0.01)
}
}
func showLoginController() {
let loginController = LoginViewController()
present(loginController, animated: true, completion: {
})
}
}
Do you have any idea why it is not working properly?

UITableView not showing in simulator

I created a tableview in Xcode 6 and hooked it up to a view controller. Whenever I try to run the app in the simulator, the tableview is not showing at all and I have no idea why. It's most confusing.
Any help would be highly appreciated.
The class:
class HomeMenuController: UIViewController, UITableViewDelegate, UITableViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int
{
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("newChecklist") as UITableViewCell
return cell
}
}
I found out how what the problem was.
The VC didn't have the 'First ViewController' option clicked. Explains it all.

Adobe Flash Builder (flex4): addChild() is not available in this class.

I want to load an swf into a flex 4 application in order to use its classes.
var ldr:Loader=new Loader();
ldr.load(new URLRequest("file://path/to/fileswf"));
ldr.contentLoaderInfo.addEventListener(Event.INIT, loaded);
function loaded(evt:Event):void { addChild(ldr); }
I receive the error:
Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.
at spark.components.supportClasses::SkinnableComponent/addChild()[E:\dev\gumbo_beta2\frameworks\projects\spark\src\spark\components\supportClasses\SkinnableComponent.as:966]
at main/private:init/loaded()[C:\Documents and Settings\ufk\Adobe Flash Builder Beta 2\xpogames-toolkit-test\src\main.mxml:22]
If I change addChild() to addElement(), I receive the following compilation error:
1067: Implicit coercion of a value of type flash.display:Loader to an unrelated type mx.core:IVisualElement. main.mxml path/dir line 22 Flex Problem
Any ideas how to resolve this issue?
Create another container to place the displayObject in:
// container ( IVisualElement ) for DisplayObjects
var container:UIComponent = new UIComponent();
addElement( container );
// displayObject goes to container
var displayO:Sprite = new Sprite();
container.addChild( displayO );
well in flash builder 4 full version, there isn't any this.rawChildren.
The best approach to resolve the issue would be to convert each required class to a flex component and to use it on your flex application:
download and install flex component kit
http://www.adobe.com/cfusion/entitlement/index.cfm?e=flex_skins
create a movie clip
convert to flex component
add the relevant functions to this class
a skeleton for a class that is attached to a movieclip that is about to be converted to a flex component:
package {
import mx.flash.UIMovieClip;
import flash.text.TextField;
import flash.events.Event;
import flash.events.MouseEvent;
public dynamic class challenge_screen extends UIMovieClip {
public function challenge_screen() {
super();
}
}
}
this.rawChildren.addChild( ldr )
should work
private var _loader:SWFLoader = new SWFLoader();
private var _uicomponent:UIComponent = new UIComponent();
private function swfLoaded(event:Event):void
{
Alert.show("inside swf Loaded");
var content:DisplayObject =_loader.content;
_uicomponent.addChild(content);
}
public function loadSWF () : void
{
_loader.addEventListener(Event.INIT, swfLoaded);
_loader.load("http://intelliveysoft.com:5080/myelearn/Admin.swf");
addElement(_uicomponent);
}
Try this. It will work

Resources