{"id":11210,"date":"2025-04-18T18:33:04","date_gmt":"2025-04-18T10:33:04","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/11210.html"},"modified":"2025-04-18T18:33:04","modified_gmt":"2025-04-18T10:33:04","slug":"android-ant-media-server-publish-webrtc-stream%e6%91%84%e5%83%8f%e5%a4%b4webrtc%e6%8e%a8%e6%b5%81%e5%88%b0%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/11210.html","title":{"rendered":"android --ant media server---Publish WebRTC Stream\u6444\u50cf\u5934WebRTC\u63a8\u6d41\u5230\u670d\u52a1\u5668"},"content":{"rendered":"<h2>Step 3: Publish a WebRTC Live Stream in Android\u200b<\/h2>\n<p>In this step, we will start coding. We will create our layout for the UI part, create an Activity and set the manifest file. Then we will be able to run our application.<\/p>\n<ul>\n<li>Create the UI part.<\/li>\n<\/ul>\n<p>First we need to create a\u00a0layout\u00a0folder under\u00a0res\u00a0directory and then we will create a xml file. For this application, a simple UI with only a\u00a0SurfaceViewRenderer\u00a0is enough.\u00a0SurfaceViewRenderer\u00a0is a\u00a0View\u00a0that is provided by the WebRTC Android SDK. We will use it to render our camera locally in our app.<\/p>\n<p>\u8fd9\u91cc\u4f1a\u4f7f\u7528SurfaceViewRenderer \u6765\u5904\u7406\u6444\u50cf\u5934\u6570\u636e<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"966\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418103301-68022a5dda3e5.png\" width=\"1283\" \/><\/p>\n<p>You can create the UI by Android Studio UI Designer or you can just copy the following lines into your xml file, say\u00a0webrtc_streaming.xml.<\/p>\n<p>\u6211\u4eec\u628a\u4e00\u4e0b\u4ee3\u7801\u590d\u5236\u5230android project\u91cc\u9762\u547d\u4ee4\u6587\u4ef6&#xff1a;webrtc_streaming.xml<\/p>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;utf-8&#034;?&gt;<br \/>\n&lt;RelativeLayout xmlns:android&#061;&#034;http:\/\/schemas.android.com\/apk\/res\/android&#034;<br \/>\n    android:layout_width&#061;&#034;match_parent&#034;<br \/>\n    android:layout_height&#061;&#034;match_parent&#034;&gt;<br \/>\n    &lt;org.webrtc.SurfaceViewRenderer<br \/>\n        android:id&#061;&#034;&#064;&#043;id\/full_screen_renderer&#034;<br \/>\n        android:layout_width&#061;&#034;match_parent&#034;<br \/>\n        android:layout_height&#061;&#034;match_parent&#034; \/&gt;<\/p>\n<p>&lt;\/RelativeLayout&gt;<\/p>\n<ul>\n<li>Create the sample Activity Now.<\/li>\n<\/ul>\n<p>We will create a Java class that extends\u00a0Activity\u00a0class. Let&#039;s name it\u00a0WebRTCStreamingActivity. In\u00a0onCreate\u00a0method, we will build an\u00a0IWebRTCClient object by configuring it and calling its\u00a0publish\u00a0method. That is all. Here is the necessary code for our activity.<\/p>\n<p>package io.antmedia.mywebrtcstreamingapp;<\/p>\n<p>import android.app.Activity;<br \/>\nimport android.os.Bundle;<br \/>\nimport io.antmedia.webrtcandroidframework.api.IWebRTCClient;<\/p>\n<p>public class WebRTCStreamingActivity extends Activity {<br \/>\n    &#064;Override<br \/>\n    protected void onCreate(Bundle savedInstanceState) {<br \/>\n        super.onCreate(savedInstanceState);<br \/>\n        setContentView(R.layout.webrtc_streaming);<\/p>\n<p>        IWebRTCClient webRTCClient &#061; IWebRTCClient.builder()<br \/>\n                .setActivity(this)<br \/>\n                .setLocalVideoRenderer(findViewById(R.id.full_screen_renderer))<br \/>\n                .setServerUrl(&#034;wss:\/\/test.antmedia.io:5443\/WebRTCAppEE\/websocket&#034;)<br \/>\n                .build();<\/p>\n<p>        webRTCClient.publish(&#034;stream1&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<ul>\n<li>Edit Android manifest file.<\/li>\n<\/ul>\n<p>We will edit two things in the\u00a0AndroidManifest.xml\u00a0file.<\/p>\n<ul>\n<li>First, we will set our WebRTCStreamingActivity as the default activity for our application.<\/li>\n<li>Second, we will add required permissions for our streaming application. Here is the edited manifest file.<\/li>\n<\/ul>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;utf-8&#034;?&gt;<br \/>\n&lt;manifest xmlns:android&#061;&#034;http:\/\/schemas.android.com\/apk\/res\/android&#034;<br \/>\n    xmlns:tools&#061;&#034;http:\/\/schemas.android.com\/tools&#034;&gt;<\/p>\n<p>    &lt;uses-feature android:name&#061;&#034;android.hardware.camera&#034; \/&gt;<br \/>\n    &lt;uses-feature android:name&#061;&#034;android.hardware.camera.autofocus&#034; \/&gt;<br \/>\n    &lt;uses-feature<br \/>\n        android:glEsVersion&#061;&#034;0x00020000&#034;<br \/>\n        android:required&#061;&#034;true&#034; \/&gt;<\/p>\n<p>    &lt;uses-permission android:name&#061;&#034;android.permission.ACCESS_NETWORK_STATE&#034; \/&gt;<br \/>\n    &lt;uses-permission android:name&#061;&#034;android.permission.BLUETOOTH&#034; \/&gt;<br \/>\n    &lt;uses-permission android:name&#061;&#034;android.permission.CAMERA&#034; \/&gt;<br \/>\n    &lt;uses-permission android:name&#061;&#034;android.permission.MODIFY_AUDIO_SETTINGS&#034; \/&gt;<br \/>\n    &lt;uses-permission android:name&#061;&#034;android.permission.INTERNET&#034; \/&gt;<br \/>\n    &lt;uses-permission android:name&#061;&#034;android.permission.BLUETOOTH_CONNECT&#034; \/&gt;<\/p>\n<p>    &lt;application<br \/>\n        android:allowBackup&#061;&#034;true&#034;<br \/>\n        android:dataExtractionRules&#061;&#034;&#064;xml\/data_extraction_rules&#034;<br \/>\n        android:fullBackupContent&#061;&#034;&#064;xml\/backup_rules&#034;<br \/>\n        android:icon&#061;&#034;&#064;mipmap\/ic_launcher&#034;<br \/>\n        android:label&#061;&#034;&#064;string\/app_name&#034;<br \/>\n        android:supportsRtl&#061;&#034;true&#034;<br \/>\n        android:theme&#061;&#034;&#064;style\/Theme.MyWebRTCStreamingApp&#034; &gt;<\/p>\n<p>        &lt;activity android:name&#061;&#034;.WebRTCStreamingActivity&#034;<br \/>\n            android:exported&#061;&#034;true&#034;<br \/>\n            android:theme&#061;&#034;&#064;style\/Theme.AppCompat.DayNight&#034;&gt;<br \/>\n            &lt;intent-filter&gt;<br \/>\n                &lt;action android:name&#061;&#034;android.intent.action.MAIN&#034; \/&gt;<\/p>\n<p>                &lt;category android:name&#061;&#034;android.intent.category.LAUNCHER&#034; \/&gt;<br \/>\n            &lt;\/intent-filter&gt;<br \/>\n        &lt;\/activity&gt;<br \/>\n    &lt;\/application&gt;<br \/>\n&lt;\/manifest&gt;<\/p>\n<p>Congratulations! Our WebRTC Android Publish Application is ready now. The project structure should be as shown in the following image, where the files we created and edited are pointed with arrows.<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1024\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418103302-68022a5e4c647.png\" width=\"908\" \/><\/p>\n<p>We can run it on an Android emulator or a real Android device after connecting to the computer. Click the Run button on Android Studio and wait for installation.<\/p>\n<p>In the first run, our application asks you to grant access. Accept them, and it will start streaming. On the Android emulator, it will be like this:<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1024\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418103302-68022a5e8a551.png\" width=\"619\" \/><\/p>\n<p>Congratulations! You are now publishing your live stream.<\/p>\n<p>To play the stream we created from our WebRTC Android Publish Application, visit\u00a0Ant Media\u2019s Test WebRTC Player, write the\u00a0stream1\u00a0to the box, and click the Start Playing button.<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"929\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418103302-68022a5ea4609.png\" width=\"1024\" \/><\/p>\n<p>\u770b\u554a&#xff1a;\u6211\u62cd\u7684\u591a\u597d&#xff1a;\u00a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"574\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418103302-68022a5edf7fb.png\" width=\"359\" \/><\/p>\n<p>\u800c\u4e14\u8fd9\u4e2a\u6d41\u5df2\u7ecf\u63a8\u52a8\u5230\u4e86android\u4ee3\u7801\u6307\u5b9a\u7684\u670d\u52a1\u5668\u4e0a\u9762\u53bb\u4e86&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"620\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418103303-68022a5f02bfd.png\" width=\"722\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb840\u6b21\uff0c\u70b9\u8d5e19\u6b21\uff0c\u6536\u85cf25\u6b21\u3002\u3010\u4ee3\u7801\u3011android &#8211;ant media server&#8212;Publish WebRTC Stream\u3002<\/p>\n","protected":false},"author":2,"featured_media":11204,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[537],"topic":[],"class_list":["post-11210","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-webrtc"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>android -ant media server-Publish WebRTC Stream\u6444\u50cf\u5934WebRTC\u63a8\u6d41\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/11210.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"android -ant media server-Publish WebRTC Stream\u6444\u50cf\u5934WebRTC\u63a8\u6d41\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb840\u6b21\uff0c\u70b9\u8d5e19\u6b21\uff0c\u6536\u85cf25\u6b21\u3002\u3010\u4ee3\u7801\u3011android --ant media server---Publish WebRTC Stream\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/11210.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T10:33:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418103301-68022a5dda3e5.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/11210.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/11210.html\",\"name\":\"android -ant media server-Publish WebRTC Stream\u6444\u50cf\u5934WebRTC\u63a8\u6d41\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T10:33:04+00:00\",\"dateModified\":\"2025-04-18T10:33:04+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/11210.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/11210.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/11210.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"android --ant media server---Publish WebRTC Stream\u6444\u50cf\u5934WebRTC\u63a8\u6d41\u5230\u670d\u52a1\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"android -ant media server-Publish WebRTC Stream\u6444\u50cf\u5934WebRTC\u63a8\u6d41\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/11210.html","og_locale":"zh_CN","og_type":"article","og_title":"android -ant media server-Publish WebRTC Stream\u6444\u50cf\u5934WebRTC\u63a8\u6d41\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb840\u6b21\uff0c\u70b9\u8d5e19\u6b21\uff0c\u6536\u85cf25\u6b21\u3002\u3010\u4ee3\u7801\u3011android --ant media server---Publish WebRTC Stream\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/11210.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T10:33:04+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418103301-68022a5dda3e5.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/11210.html","url":"https:\/\/www.wsisp.com\/helps\/11210.html","name":"android -ant media server-Publish WebRTC Stream\u6444\u50cf\u5934WebRTC\u63a8\u6d41\u5230\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T10:33:04+00:00","dateModified":"2025-04-18T10:33:04+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/11210.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/11210.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/11210.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"android --ant media server---Publish WebRTC Stream\u6444\u50cf\u5934WebRTC\u63a8\u6d41\u5230\u670d\u52a1\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/11210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=11210"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/11210\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/11204"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=11210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=11210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=11210"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=11210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}