The simplest example of mobile terminal based on FFmpeg attachment: built-in Android player, ffmpegandroid

Source: Internet
Author: User

The simplest example of mobile terminal based on FFmpeg attachment: built-in Android player, ffmpegandroid
Previous articles record FFmpeg-based multimedia programs on the Android platform. For comparison, this article records a Video Player Based on the android Multimedia Framework OpenCore.
The use of multimedia frameworks provided by Android is much simpler than porting FFmpeg. You only need to call several interface functions to control video playback. We will not record its usage too much.

Source code

The directory structure of the project. The Java source code is located in the src directory.


The Java code of the Android program is located in src \ com \ leixiao00001020 \ sandroidplayer \ MainActivity. java, as shown below.
/* The Simplest Android video Player * Simplest Android Player ** Lei Xiaohua * leixiaohua1020@126.com * China Media University/Digital TV technology * Communication University of China/Digital TV technology * http://blog.csdn.net/leixiaohua1020 ** this program is based on Android interface video player. ** Video player based on Android API. **/package com. leixiao00001020.sandroidplayer; import android. OS. bundle; import android. OS. environment; import android. app. activity; import android. util. log; import android. view. menu; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. editText; import android. widget. videoView; public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); final VideoView videoView = (VideoView) findViewById (R. id. videoView1); Button setButton = (Button) this. findViewById (R. id. button_set); Button startButton = (Button) this. findViewById (R. id. button_start); Button pauseButton = (Button) this. findViewById (R. id. button_pause); Button stopButton = (Button) this. findViewById (R. id. button_stop); final EditText urlEdittext = (EditText) this. findViewById (R. id. input_url); setButton. setOnClickListener (new OnClickListener () {public void onClick (View arg0) {String folderurl = Environment. getExternalStorageDirectory (). getPath (); String urltext = urlEdittext. getText (). toString (); // Small FIX, Avoid '/' if (urltext. charAt (0) = '/') {urltext = urltext. substring (1);} String inputurl = folderurl + "/" + urltext; Log. e ("url", inputurl); videoView. setVideoPath (inputurl); // videoView. setMediaController (new MediaController (MainActivity. this) ;}}); startButton. setOnClickListener (new OnClickListener () {public void onClick (View arg0) {videoView. start () ;}}); pauseButton. setOnClickListener (new OnClickListener () {public void onClick (View arg0) {videoView. pause () ;}}); stopButton. setOnClickListener (new OnClickListener () {public void onClick (View arg0) {videoView. stopPlayback () ;}}) ;}@ Override public boolean onCreateOptionsMenu (Menu menu) {// Inflate the Menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. main, menu); return true ;}}

Running result

The result of the App running on the mobile phone is shown in. You can click the "Set", "Start", "Pause", and "Stop" buttons to perform different operations on the video.

Note that you need to copy the video file waiting for playback to the corresponding directory on the memory card. For example, copy sintel.mp4 to the root directory of the memory card.



Download
Simplest ffmpeg mobile


Project Homepage

Github: https://github.com/leixiaohua1020/simplest_ffmpeg_mobile

Open source China: https://git.oschina.net/leixiaohua1020/simplest_ffmpeg_mobile


CSDN project: http://download.csdn.net/detail/leixiaohua1020/8924391


This solution contains various examples of using FFmpeg to process multimedia on mobile terminals:
[Android]
Simplest_android_player: Android-Based Video Player
Simplest_ffmpeg_android_helloworld: The FFmpeg-based HelloWorld program in Android
Simplest_ffmpeg_android_decoder: the simplest FFmpeg-based video decoder on Android
Simplest_ffmpeg_android_decoder_onelib: the simplest FFmpeg-Based Video Decoder for Android-single library
Simplest_ffmpeg_android_streamer: the simplest FFmpeg-based streamer on Android
Simplest_ffmpeg_android_transcoder: The FFmpeg command line tool transplanted on the Android platform
Simplest_sdl_android_helloworld: the simplest program to port SDL to Android.
[IOS]
Simplest_ios_player: A Video Player Based on the IOS Interface
Simplest_ffmpeg_ios_helloworld: The FFmpeg-based HelloWorld program in IOS
Simplest_ffmpeg_ios_decoder: the simplest FFmpeg-based video decoder on IOS
Simplest_ffmpeg_ios_streamer: the simplest FFmpeg-based streamer on IOS
Simplest_ffmpeg_ios_transcoder: The ffmpeg. c command line tool transplanted on the IOS platform
Simplest_sdl_ios_helloworld: the simplest program to port SDL to IOS.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.