Image copyright ABC

US President Barack Obama has urged police and black communities to come together, saying it should not be "us versus them", in a town hall meeting on race and policing.

Mr Obama and ABC News held the forum amid an increase in racial tensions in the US in recent weeks.

Last week a gunman killed five Dallas police at a Black Lives Matter protest.

Micah Xavier Johnson told police he was angry after recent shooting deaths of black men at the hands of officers.

Alton Sterling was killed by police in Baton Rouge, Louisiana, on 5 July. A day later, Philando Castile was shot and killed during a traffic stop outside Minneapolis, Minnesota.

Videos of both shootings were widely publicised.

"I don't want a generation of young people to grow up thinking either that they have to mistrust the police or alternatively, that the police who are doing a good job and out there... that they're constantly at risk not just from criminals but also because the community mistrusts them," Mr Obama said.

He added: "It's going to require all of us not to close ourselves off and go to corners but rather require us to come together and listen to each other."

Obama as consoler-in-chief - Rajini Vaidyanathan, BBC News

Media playback is unsupported on your device Media caption Obama reassures Alton Sterling's son

In the wake of shootings in recent years, President Obama has delivered passionate sermons on what needs to be done to repair the strained relationship between the police and minority communities. For this town hall format, President Obama swapped the oratory for empathy, as he fielded questions from a range of people who had a very personal stake in the issue.

"How do we as a nation, stop what is happening?" asked Diamond Reynolds, the girlfriend of Philando Castle, who was shot by police in Minnesota. "I ask for your help," was the plea from the son of Alton Sterling, who was killed in Baton Rouge. How can my police officer son stay safe, after he was attacked, asked Terri, the mother of a Baltimore police officer.

For this town hall, Mr Obama's role was more consoler-in-chief, soothing some of the raw grief felt by families and the police. Some of the underlying problems were examined, but a discussion on solutions was lacking.

The President's taskforce on community policing was set up two years ago - the fact we are seeing yet another town hall full of victims families, is a reminder that the pace of reform is slow.

Read more: Has anything changed since Ferguson?

Guests in the town hall meeting included Sterling's 15-year-old son, Cameron, and Castile's girlfriend, Diamond Reynolds - who ​live streamed​ the aftermath of Castile's shooting.

Mr Obama tried to bridge the divide between police and the black community.

He empathised with victims of police violence but also acknowledged that police face huge challenges - challenges they can't handle alone.

"It is absolutely true that the murder rate in the African-American community is way out of whack compared to the general population," Mr Obama said in response to a question from Milwaukee Police Chief Edward Flynn.

"We can't put the burden on police alone," Mr Obama said. "It is going to require investments in those communities."

Media playback is unsupported on your device Media caption Obama talks about experiencing racism as a child

Mr Obama also offered a rare personal account about how he has been affected by racism.

He talked about how, when he was a child growing up in Hawaii, a female neighbour once refused to go in a lift with him.

She was just "worried about riding the elevator with me," Mr Obama said.

He said that sense of being feared as a black man continued as he grew older.

"Over time you start learning as you're crossing the street, suddenly the locks start going on doors," Mr Obama said.

In one tense exchange, Texas Lt Governor Dan Patrick - who has been critical of the Black Lives Matter movement and the president - pressed Mr Obama on his commitment to law enforcement.

Mr Obama insisted that it was possible to be critical of police while still being supportive.

"We shouldn't get too caught up in this notion that somehow people who are asking for fair treatment are somehow automatically anti-police," the president said.