Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

506
Vistas
iOS: How to intercept and manipulate bytes in AVPlayer

Is there a way to intercept byte data and perform a XOR operation to each byte prior to playing audio in AVPlayer?

I'm building an audio streaming app and use a little script written in C to add a simple layer of encryption to the MP3 files. In Android it gets decoded in real time like this:

@Override
public int read(byte[] buffer, int offset, int readLength) throws FileDataSourceException {
        // ...
        if (readLength == 1 && offset >= 1 && offset <= 123) {
            buffer[offset] = (byte)(buffer[offset] ^ 11);
        }

        return bytesRead;
    }
}

As you can see above reversing the XOR encryption is fairly easy in Android as I use ExoPlayer and override the read() method in its datasource classes. Is there any chance to perform the same thing using AVPlayer with Swift?

Here's a flowchart of the whole idea:

AVPlayer encryption flowchart

Thank you.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You'll want to use MTAudioProcessingTap for this, which is a property of AVPlayer's AVAudioMix. In your tap process callback, use MTAudioProcessingTapGetSourceAudio to grab your buffers. Once you have your buffer reference you can xor the data.

There's some boilerplate needed to get the AVAudioMix and MTAudioProcessingTap setup properly. The sample code that Apple has is pretty old, but still should work. https://developer.apple.com/library/archive/samplecode/AudioTapProcessor/Introduction/Intro.html#//apple_ref/doc/uid/DTS40012324

Also note that it will be easier to do this in Objective C, for several reasons. The interop with your C file will be easier, and it is much more straightforward reading/writing to the buffer in Objc. It will also run faster than in swift. If you are interested to seeing what this would look like in swift, there is a sample project here: https://github.com/gchilds/MTAudioProcessingTap-in-Swift

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda