GithubHelp home page GithubHelp logo

firefoxyo / android-a2dpsink Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aystshen/android-a2dpsink

0.0 0.0 0.0 21 KB

Apply patches to enable Android to support the Bluetooth a2dpsink protocol, which allows Android to work like a Bluetooth speaker for audio output.

Java 100.00%

android-a2dpsink's Introduction

Android-A2dpSink

Apply patches to enable Android to support the Bluetooth a2dpsink protocol, which allows Android to work like a Bluetooth speaker for audio output.

  • a2dpsink_android5.1.patch for android 5.1
  • a2dpsink_android8.1.patch for android 8.1

Integration

  1. Apply a2dpsink_android5.1.patch or a2dpsink_android8.1.patch.
  2. Recompile Android.

Usage

  1. Open this Android device Settings->Bluetooth page, then open Bluetooth.
  2. The mobile phone connects to this Android device just like a Bluetooth headset.
  3. The phone plays music, at this time the Android device will be able to play the music in the phone.

Get media information

At this point, you can play music. If you need to get the song information being played, you can operate as follows.

public class A2dpSinkPresenter {
    private static final String TAG = "A2dpSinkPresenter";

    private static final String ACTION_TRACK_EVENT =
            "android.bluetooth.avrcp-controller.profile.action.TRACK_EVENT";
    public static final String EXTRA_METADATA =
            "android.bluetooth.avrcp-controller.profile.extra.METADATA";
    public static final String EXTRA_PLAYBACK =
            "android.bluetooth.avrcp-controller.profile.extra.PLAYBACK";

    private Context mContext;
    private IA2dpSinkView mA2dpSinkView;

    public A2dpSinkPresenter(Context context, IA2dpSinkView view) {
        mContext = context;
        mA2dpSinkView = view;
    }

    public void start() {
        IntentFilter filter = new IntentFilter();
        filter.addAction(ACTION_TRACK_EVENT);
        mContext.registerReceiver(mBtReceiver, filter);
    }

    public void stop() {
        mContext.unregisterReceiver(mBtReceiver);
    }

    private BroadcastReceiver mBtReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "onReceive intent=" + intent);
            String action = intent.getAction();

            if (ACTION_TRACK_EVENT.equals(action)) {
                PlaybackState pbb = intent.getParcelableExtra(EXTRA_PLAYBACK);
                MediaMetadata mmd = intent.getParcelableExtra(EXTRA_METADATA);
                if (null != mmd) {
                    mA2dpSinkView.updateA2dpSinkMediaInfo(mmd);
                }
            }
        }
    };
}

Developed By

License

Copyright 2019 Bob Shen

Licensed under the Apache License, Version 2.0 (the "License"); you may 
not use this file except in compliance with the License. You may obtain 
a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
License for the specific language governing permissions and limitations 
under the License.

android-a2dpsink's People

Contributors

aystshen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.