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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -