nickropes nickropes - 2 months ago 39
iOS Question

How to rename Done button in AVPlayer?

I'm developing an app in Swift 3.0 that gives users the chance to stream TV channels online. It is restricted to Italy at the time, so I'm trying to translate every button in the app in Italian... but I'm having problems for the Done button (and the "Live streaming" field) at the top of the AVPlayer screen that appears whenever the user chooses a channel to stream. I'm sure there's a way to edit them, because when I open a stream in Safari, the Done button is correctly displayed as "Fine" and "Live streaming" becomes "Trasmissione in diretta"... I'd like to see them this way too but I have no idea of the way to reach that goal.

I haven't made any specific class for the player, just created a segue from the storyboard to the AVPlayerController, and I manage streams entirely from the table view that contains the channels; here's my significant code:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "guardaCanale" {
let destinazione = segue.destination as! AVPlayerViewController
if let cellaCanaleSelezionata = sender as? CanaleTableViewCell {
let indexPath = tableView.indexPath(for: cellaCanaleSelezionata)!
let canaleSelezionato = ritornaIlCanaleCorretto(indexPath: indexPath)

let url = URL(string: canaleSelezionato.urlCanale)
if let streamingURL = url {
destinazione.player = AVPlayer(url: streamingURL)

// Il do-try-catch seguente serve per far funzionare l'audio dell'app anche se l'iPhone è in modalità silenziosa; togli il blocco per fare in modo che l'app non produca audio se l'iPhone è in modalità silenziosa
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch {
print("Errore: non riesco a riprodurre l'audio se iPhone è in modalità silenziosa.")

Anyone can help me please? I don't want to modify the Done button behavior, just change its visible name onscreen... hope someone could help me! Thank you so much! :)


It sounds like you haven't properly setup your app for Italian localization.

Translation for Apple provided UI elements is based on the language of the device and whether or not your app supports that language. If you change the devices language to Italian, this is what it should show automatically.

enter image description here

I'd suggest reading Apple's Localization Documentation to make sure you are properly setting up you app so the system knows it's localized for Italian.