c# - StreamType deprecated. How to get the stream type? -


i'm trying implement playsound() method should play default notification sound. work perfectly. here's code:

    public void playsound()     {         mediaplayer mediaplayer = new mediaplayer();          var notification = ringtonemanager.getdefaulturi(ringtonetype.notification);         mediaplayer.setdatasource(application.context, notification);         ringtone r = ringtonemanager.getringtone(application.context, notification);         mediaplayer.setaudiostreamtype(r.streamtype);         mediaplayer.prepare();         mediaplayer.start();     } 

the compiler tells me r.streamtype deprecated. i've looked @ various locations can't find 'new' way streamtype. know?

api 21 added mediaplayer.setaudiostreamtype replace mediaplayer.setaudiostreamtype, can runtime check determine api methods use:

if (build.version.sdkint >= buildversioncodes.lollipop) {     var attribs = new audioattributes.builder().setflags(audioflags.none).setlegacystreamtype(stream.ring).build();     mediaplayer.setaudioattributes(attribs); } else {     mediaplayer.setaudiostreamtype(r.streamtype); } 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -